Temperature Conversions. The following problems generate temperature- conversion
ID: 3549744 • Letter: T
Question
Temperature Conversions. The following problems generate temperature- conversion tables. Use following equations that give relationships between temperatures in degrees Fahrenheit(Tf), degree Celsius(Tc), degrees Kelvin(Tk), and degrees Rankin(Tr);
Tf=Tr-459.67R
Tf=(9/5)Tc+32F
Tr=(9/5)Tk
Write a program to generate a table of conversions from Fahrenheit to Kelvin for values from 0 F to 200 F. Allow the user to enter the increment in degrees Fahrenheit between lines. Use a (do while loop) in your solution.
Explanation / Answer
#include
#include
using namespace std;
int main()
{
// Variable declaration section
float sourceTemperature, answer, menuChoice;
cout<< " Please choose one of the following: ";
cout<< " 1. Farenheit to Celsius ";
cout<< " 2. Celsius to Farenheit ";
cout<< " 3. Exit from program ";
cout<< "Your choice: ";
cin>> menuChoice; // Read in the desired menu choice
// Process menu option
if (menuChoice == 3) { // If menu choice was 3, exit from program
exit( 0); // normal program termination
}
if (menuChoice > 3) { // Abort on invalid menu options
cout<< "*** Invalid menu option entered.*** Aborting... ";
exit( -1); // Abnormal program termination
}
//Prompt for temperature
cout<< "Please enter the source temperature: ";
cin>> sourceTemperature;
// Calculate correct answer depending on menu selection
if (menuChoice == 1) { //F. to C.
answer = (sourceTemperature - 32) * 5.0/9.0;
}
else if (menuChoice == 2) { // C. to F.
answer = sourceTemperature * 9.0/5.0 + 32;
}
else { // This should never be executed!
cout<< "***Sanity check failed. Invalid menuChoice*** Aborting... ";
exit( -1); // leave the program
}
cout<< sourceTemperature << " converted is: " << answer << endl;
return 0;
}
plz rate my answer..
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.