Ok. So, I have just started up my intro to programming class and am already confused. For this project we are supposed to be converting temperature from fahrenheit to centigrade. Now, my instructor has already given me this sample code to work with.
Sample Code
The code snippet below converts a temperature inputted in Fahrenheit to Centigrade.
//Declare variables for keeping temperature in Fahrenheit and Centigrade
double f, c;
//Input temperature in Fahrenheit as a String
cout << “Enter temperature in Fahrenheit: “ << endl;
cin >> f;
//Convert Fahrenheit temperature in Centigrade
c = (5.0 / 9.0) * (f – 32.0);
That is the sample code above. Here is what I inputted.
#include <iostream>
using namespace std;
int main()
{
//Declare variables for keeping temperature in Fahrenheit and Centigrade
double f,c;
//Input temperature in Fahrenheit as a String
cout << "Enter temperature in fahrenheit: " <<endl;
cin >> f;
c = (5.0 / 9.0)*(f – 32.0);
cout << "The conversion of fahrenheit to centigrade: " << c << endl;
return 0;
}
And I get an error code with the compiler on line 24. I don't understand what's wrong here. Am I supposed to declare another variable? Thank you. I'm already seriously behind and Computer Science is my major!!!!
Also, when asking for the temperature. You can take out that endl. That way the value will be entered in after the colon. I think it looks better that way.
Oh yeah, for some reason the - sign never took. So I did retype it and it worked fine. Thank you AbstractionAnon. This is all new to me, including this forum. lol.