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

Quote:
#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

Windows 8.1 Professional x64
 
 

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 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

Windows 8.1 Professional x64
 
 

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
Reply

 C++ help, Homework assignment





Thread Tools



Similar help and support threads for2: C++ help, Homework assignment
Thread Forum
Blue Screen of death while doing homework, watching flash video BSOD Help and Support
BSOD While Children Just Type Out Homework BSOD Help and Support
Solved Need help with a couple of homework questions?? General Discussion
Do your Office Starter 2010 homework News
Syncing Music/Homework folders between computers Network & Sharing
Homework Please HELPP...!! Network & Sharing
IRQ Assignment Installation & Setup

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 09:23 PM.
Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App
  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33