C++ help, Homework assignment

chris1neji

New member
Guru
Local time
4:41 PM
Messages
480
Location
Somewhere in California
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 Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Gateway / Slight Modifications
OS
Windows 8 64 bit PRO
CPU
AMD Phenom X4 9100e
Motherboard
Gateway RS780
Memory
2GB X2 DDR2
Graphics Card(s)
Sapphire HD 6850
Sound Card
Integrated
Monitor(s) Displays
Gateway 19" + Dell 19"
Screen Resolution
1440X900 sometimes 2880 by 900
Hard Drives
WD 80GB
WD 640GB
WD 1,000GB
PSU
Antec BP 550watts
Case
Antec 300
Cooling
Stock Cooling
Keyboard
Saitek Eclipse II
Mouse
Gigabyte GM-M6800
Internet Speed
D: 30Mbps U:4Mbps
Antivirus
Avast version 8
Browser
Internet Explorer ver 10 64 bit
Other Info
This is my work computer.
I have another laptop running Windows 7 64 bit.
Another PC running Windows 8 64 bit pro.
Total of 3
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 Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Custom Built
OS
Windows 8.1 Pro x64
CPU
Intel Core i7 4790k
Motherboard
MSI Z97S Krait Edition
Memory
8GB Corsair Dominator 1600MHz
Graphics Card(s)
MSI TwinFrozr GeForce GTX770
Sound Card
ASUS Xonar DX/XD 7.1
Monitor(s) Displays
Dell 24" S2409W + Dell 20" E207WFP
Screen Resolution
1920x1080 + 1680x1050
Hard Drives
1x 120GB OCZ Agility 3, 1x 750GB Western Digital Caviar Black, 1x 1TB Western Digital Caviar Blue
PSU
Corsair HX850 modular
Case
Fractal Design Define R4
Cooling
Corsair H60 w/ twin Corsair SP120 fans
Keyboard
Logitech G510S Keyboard
Mouse
Logitech G500S Laser Mouse
Internet Speed
40Mbps
Antivirus
Microsoft Security Essentials
Browser
Google Chrome
Other Info
LG Blu-Ray player
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 Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Gateway / Slight Modifications
OS
Windows 8 64 bit PRO
CPU
AMD Phenom X4 9100e
Motherboard
Gateway RS780
Memory
2GB X2 DDR2
Graphics Card(s)
Sapphire HD 6850
Sound Card
Integrated
Monitor(s) Displays
Gateway 19" + Dell 19"
Screen Resolution
1440X900 sometimes 2880 by 900
Hard Drives
WD 80GB
WD 640GB
WD 1,000GB
PSU
Antec BP 550watts
Case
Antec 300
Cooling
Stock Cooling
Keyboard
Saitek Eclipse II
Mouse
Gigabyte GM-M6800
Internet Speed
D: 30Mbps U:4Mbps
Antivirus
Avast version 8
Browser
Internet Explorer ver 10 64 bit
Other Info
This is my work computer.
I have another laptop running Windows 7 64 bit.
Another PC running Windows 8 64 bit pro.
Total of 3
Good to hear :)

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

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Custom Built
OS
Windows 8.1 Pro x64
CPU
Intel Core i7 4790k
Motherboard
MSI Z97S Krait Edition
Memory
8GB Corsair Dominator 1600MHz
Graphics Card(s)
MSI TwinFrozr GeForce GTX770
Sound Card
ASUS Xonar DX/XD 7.1
Monitor(s) Displays
Dell 24" S2409W + Dell 20" E207WFP
Screen Resolution
1920x1080 + 1680x1050
Hard Drives
1x 120GB OCZ Agility 3, 1x 750GB Western Digital Caviar Black, 1x 1TB Western Digital Caviar Blue
PSU
Corsair HX850 modular
Case
Fractal Design Define R4
Cooling
Corsair H60 w/ twin Corsair SP120 fans
Keyboard
Logitech G510S Keyboard
Mouse
Logitech G500S Laser Mouse
Internet Speed
40Mbps
Antivirus
Microsoft Security Essentials
Browser
Google Chrome
Other Info
LG Blu-Ray player
Back
Top