Join Forum | Login | Today's Posts | Tutorials | Windows 10 Forum | Windows 8 Forum

 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 chris1neji Windows 8 64 bit PRO 494 posts Somewhere in California 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 Quote: #include #include 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 Specs
 16 Sep 2012 #2 Everlong Windows 8.1 Pro x64 3,423 posts Morecambe, Lancashire, England 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: Code: ```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 Specs
 16 Sep 2012 #3 chris1neji Windows 8 64 bit PRO 494 posts Somewhere in California 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 Specs
 .
 17 Sep 2012 #4 Everlong Windows 8.1 Pro x64 3,423 posts Morecambe, Lancashire, England 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 Specs