Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.

Windows 7: C++ help, Homework assignment

16 Sep 2012   #1

Windows 8 64 bit PRO
C++ help, Homework assignment

So i was wondering if anyone could help me out on my homework assignment
So far were just starting this is week 4. I need assistance trying to convert fahrenheit to kelvin
this is what i have so far

#include <iostream>
#include <iomanip>
using namespace std;
int main()
// originally was just fah and kelvin. extraa kelvins were added in order to attempt to gain correct output.
// output remains 273 which is incorrect
float fah, kelvin0, kelvin1, kelvin2;
//fix and setp so it can round to ones decimal places
cout << fixed;
cout << setprecision(1);
cout << "== Fahrenheit to Kelvin converter ==" << endl;
cout <<"Enter Fahrenheit:" << endl;
cin >> fah ;
// calculation has been seperated into parts indiviually because the result being output is incorrect
// the result is always 273 original formula was kelvin = (fah - 32) * (5 / 9) + 273.15
kelvin0 = (fah - 32);
kelvin1 = kelvin0 * (5/9);
kelvin2 = kelvin1 + 273.15;

cout << "Kelvin: " << kelvin2 << endl;

My comments describe my error but if you cant read them for some reason. it // calculation has been seperated into parts indiviually because the result being output is incorrect
// the result is always 273 original formula was kelvin = (fah - 32) * (5 / 9) + 273.15

Also do you guys know of a great forum that deals with C++/ assisting in homework C++ related?

i think i am going to need C++ friends in order to succeed in this class.
My System SpecsSystem Spec
16 Sep 2012   #2


Because you're working with floats, you need to define numbers with a decimal place. The error occurs because when 5/9 is calculated, it returns the result as just 0.

So change numbers like 32, 5, 9 to 32.0, 5.0, 9.0.

For aesthetic purposes as well, you could also change the lines of code that deal with conversion to just a single line:

kelvin = 273.15 + ((fah - 32.0) + (5.0/9.0));
cout << "Kelvin: " << kelvin << endl;
A good site to get help with for C++ is either stackoverflow or dani web, or just shoot me a PM whenever and I'll help with what I can. You'll get your head around C++ soon enough.
My System SpecsSystem Spec
16 Sep 2012   #3

Windows 8 64 bit PRO

Thank you so much it did work I looked at it and I made a small adjustment

((fah - 32.0) + (5.0/9.0)); to ((fah - 32.0) * (5.0/9.0));
My System SpecsSystem Spec

17 Sep 2012   #4


Good to hear

Yea, you were right to make that change. I was quite tired and it was a mistake on my behalf.
My System SpecsSystem Spec

Thread Tools

Similar help and support threads
Thread Forum
BSOD while doing homework / running queries in SAS
BSOD mentioned atikmpag.sys sounds like removing and updating my ATI drivers would be the best bet?
BSOD Help and Support
BSOD While Children Just Type Out Homework
I have been getting BSOD for no reason that I can understand. Checking the logs I see issues starting with something called SuperFetch but only can find a site. No software seems to be install but I haven't a clue. Any help would be greatly respected. ZMan
BSOD Help and Support
Need help with a couple of homework questions??
I am working with a computer that has a total storage space of 1TB...of this total space I have used 78GB. 1. Assuming that I should not use more than 85% of the total available space, how much total storage should I use? 2. If I use an average of 500MB of storage each week, how many weeks...
General Discussion
Do your Office Starter 2010 homework
Source - Retail customers: Do your Office Starter 2010 homework | ZDNet
Homework Please HELPP...!!
hi, my professor gave me a homework 2 days ago and tomorrow morning is due and i dont know shit, im supposed to know this because im majoring in computer science and networking... he gave me 10 questions to answer which i just answered 3... here are some questions that maybe you can help me with.....
Network & Sharing

Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 02:42.
Twitter Facebook Google+ Seven Forums iOS App Seven Forums Android App