I need to say that I am new to c++. i bought the "C++ for Dummies" book, and it came with a CodeBlock CD inside. Once i finished my first program (a celsius to fahrenheit converter) i thought that i could do a fahrenheit to celsius converter by just changing the equations and factors, and all the fahrenheit words to celsius, and vise-versa. After correcting a few errors, i was finally able to run it. But, once i entered a temperature in Fahrenheit, the Celsius was said to be 0 every time. Please help me.
This is the code Ive got so far:
//
// Conversion - Program to convert temperature from
// Fahrenheit degrees into Celsius:
// Celsius = 5.0/9.0 * (Fahrenheit - 32.0)
//
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
int main (int nNumberofArgs, char* pszArgs[])
{
// enter the temperature in Fahrenheit
int fahrenheit;
cout << "Enter the temperature in Fahrenheit:";
cin >> fahrenheit;
// calculate conversion factor for Fahrenheit
// to Celsius
int factor;
factor = 5.0 / 9.0;
// use conversion factor to convert Fahrenheit
// into Celsius values
int celsius;
celsius = factor * (fahrenheit - 32.0);
// output the results (followed by a NewLine)
cout << "Celsius value is:";
cout << celsius << endl;
// wait until user is ready before terminating program
// to allow the user to see the program results
system("PAUSE");
return 0;
}
Thanks for the help in advance!! Also, e-mail me at adl-94@hotmail.com
You will find it to be easier to contact me through there.
This post has been edited by mralchamp: 29 June 2009 - 10:07 AM

New Topic/Question
Reply




MultiQuote




|