You will be converting the current temperature from Fahrenheit to Celsius. To convert to Celsius (C), subtract 32 from the user's number, then multiply by 5 and divide by 9. This exercise is testing your mastery of operator precedence (order of operations).
Output:
Enter the current outdoor temperature in Fahrenheit: [assume user inputs 80]
It is 26.6667 degrees Celsius outside.
// Converting the current temperature from Fahrenheit to Celsius
// the preprocessing directives
#include <iostream> // cin, cout
using namespace std;
int main()
{
// declare the variables
double Fahr, Cels;
cout << "Enter the current outdoor temperature in Fahrenheit: ";
cin>>Fahr;
Cels = (Fahr-32)*5/9;
cout<<"It is "<<Cels<<" degrees Celsius outside."<<endl;
return 0;
}
Comments
Leave a comment