|
Answer» i just started to read C++ for dummys and i have coded a CONVERTER for tempature using the tutorial and when i run it through the compiler i get an error on line 13, the complier im using is dev C++ ....
could some one look through the code to see what the mistake is .. i have just started to LEAN C++
Code: [Select]// // Program to convert temperature from Celsius degree units: // units into Fahrenheit degree units: // Farhrenheit = Celsius *(212 - 32)/100 +32 // #include <cstdio> #include <cstdlib> 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 cinversion factor for Celsius // to Fahrenheit intfactor; factor = 212 -32;
// use conversion factor to convert Celsius // into Fahrenheit values int fahrenheit; fahrenheit = factor * celsius/100 + 32 ;
//output the results (followed by Newline) cout << Fahrenheit value is :"; cout << fahrenheit << endl ;
// wait untill user is READY befor terminating program // to allow the user to see the program results system( "PAUSE"); RETURN 0; } Not knowing much about C++, I found all the corrections on Google (hint, hint)
Code: [Select]// // Program to convert temperature from Celsius degree units: // units into Fahrenheit degree units: // Farhrenheit = Celsius *(212 - 32)/100 +32 // #include <cstdio> #include <cstdlib> #include <iostream> 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 cinversion factor for Celsius // to Fahrenheit int factor; factor = 212 -32;
// use conversion factor to convert Celsius // into Fahrenheit values int fahrenheit; fahrenheit = factor * celsius/100 + 32 ;
//output the results (followed by Newline) cout << "Fahrenheit value is :"; cout << fahrenheit << endl ;
// wait untill user is ready befor terminating program // to allow the user to see the program results system( "PAUSE"); return 0; }
1) cout and cin require a #include <iostream> statement 2) intfactor - two words; it's a declaration not a variable name 3) RETURN works as lowercase; C++ must be case sensitive
Once the compiler bugs are worked out, the program seems to work. Any plans to convert Fahrenheit to Celsius?
Good luck.
|