I just got a Dummies book on C++, and I tried writing a
program, that my computer's having trouble compiling, I thought someone might know what's wrong. I tried to write the Celsius Conversion Program, and something went haywire.
I just got a Dummies book on C++, and I tried writing a
program, that my computer's having trouble compiling, I thought someone might know what's wrong. I tried to write the Celsius Conversion Program, and something went haywire.
First off welcome to the boards.
In the future please post the code when it is short instead of attaching it.
Please read http://cboard.cprogramming.com/showthread.php?t=13473 on details on how to do that.
Ok in this program you are making serveral mistakes:Code:// // Program to convert temperature from Celsius degree // units into Fahrenheit degree units: // Fahrenheit = Celsius * (212 - 32)/100 + 32 // #include <cstudio> #include <cstdlib> #include <isostream> using namespace std; int main(int nNumberofArgs, char* pszArgs[]) { // enter the temperature in Celsius int celsius; cout << "Enter the temperature in Celsius" cin >>> celsius; // calculate conversion factor for Celsius // to Fahrenheit int factor; factor = 212 - 32; // output the results (followed by a NewLine) cout << "Fahrenheit value is:"; cout << fahrenheit << endl; // wait until user is ready before terminating program // to allow the user to see the program system("PAUSE"); return 0;
1) You get a value for celsius from the user but never use it to calculate fahrenheit.
2) The standard formula for calculating Fahrenheit from Celsius is:
F = (9/5)C + 32
3) You are trying to use fahrenheit prior to declaring it
Search the boards, this is a very common program.
had a couple of errors:
Code:// // Program to convert temperature from Celsius degree // units into Fahrenheit degree units: // Fahrenheit = Celsius * (212 - 32)/100 + 32 // #include <iostream> //its not isostream its iostream using namespace std; int main() { // enter the temperature in Celsius int celcius; //spelled celcius wrong cout << "Enter the temperature in Celsius";//forgot to end the statement with ";" cin >> celcius; // had too many ">" // calculate conversion factor for Celsius // to Fahrenheit float fahrenheit; //must be float number so decimals can be used fahrenheit = celcius*(9/5)+ 32; // output the results (followed by a NewLine) cout << "Fahrenheit value is:"; cout << fahrenheit << endl; // wait until user is ready before terminating program // to allow the user to see the program system("PAUSE"); return 0; } //no end paranthases