Output a prompt using the cerr object that instructs the user to type in a temperature in °F (i.e. Fahrenheit).
Define a variable named tempF of type int.
Read the input into the tempF variable using the cin object.
cin >> tempF;
Define a variable named tempK of type double.
Convert the °F value to Kelvin using the following arithmetic expression storing the result of the expression in the tempK variable.
(tempF + 459.67) * 5 ÷ 9
Use the cout object to print the following output.
tempF degree Fahrenheit in Kelvin is tempK
Example output when the input is 72.
72 degree Fahrenheit in Kelvin is 295.372
Be sure to end the output of this part with a newline.
Part I
Insert the following statement into your program.
cout << 5/9 << endl;
Using only one cout statement, print a short explanation as to why the previous cout statement printed the value 0 (zero).
cout << "5/9 prints 0 because ..." << endl;
What's wrong with your code? Can you tell us what compile errors you're getting, show us the entire code, and tell us which lines are giving you the errors?
...
..
.
cout << tempF << " degree Fahrenheit in Kelvin is " << tempK << endl;
cout <<"5/9 prints 0 because in C++ the result of dividing an integer by an integer is truncated to an integer <<
endl;
}
Is that enough? what is these for--cin.get(); and return 0; Do I have to write?
It's generally a bad idea to mix cin.get with cin so you should just leave it out and have the program end with "return 0;", which basically ends the main function as false - ending the program.
Your answer to Part 1 looks fine so long as you're formatting it correctly:
1 2
cout << tempF << " degree Fahrenheit in Kelvin is " << tempK << endl;
cout << "5/9 prints 0 because in C++ the result of dividing an integer by an integer is truncated to an integer" << endl;