I'm in a cpp class in high school, and I'm using what I've learned in there so far to try and make my own program without code samples. This isn't a required thing, it's just for fun. It's a Fahrenheit to Celsius converter... Here is the code: Other than that, this is the error: http://screensnapr.com/e/ET44vX.png
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
// Fahrenheit to Celsius Converter
// November 5th, 2011
#include <iostream>
usingnamespace std;
int main()
{
int fahr;
int cels;
cout << "Fahrenheit to Celsius Converter\n";
cels = (fahr - 32) * 5 / 9;
cout << "Enter temperature in fahrenheit: ";
cin >> fahr;
cout << "The temperature in Celsius is: " << cels << '\n';
system("pause");
return 0;
}
It'd typical to make this mistake when begining to learn to program, I myself made this same mistake.
What you did wrong here was to put the equation to convert from fahrenheit to celcius before you had the user enter in a value for Fahr.
Also I would change the fahr from int to say a float variable since not all values will be in integer format and that will account to a loss precision.