Write a function that displays a menu that allows the user to do the following:
ID: 3781162 • Letter: W
Question
Write a function that displays a menu that allows the user to do the following: Convert a temperature from Celsius to Fahrenheit using the formula F = 9/5 C + 32. Convert a temperature from Fahrenheit to Celsius using the formula C = 5/9 (F - 32) Quit the program. Read the choice from the user. If the user chose 1 or 2, first call a subroutine to get a temperature from the user. Then, pass the temperature as a parameter to the appropriate function and return the converted temperature. Output the returned converted temperature, and then display the menu once again. If the user chose 3. quit the program. A sample run is included below: Fahrenheit to Celsius Celsius to Fahrenheit Quit Please select one of the above: 1 Please enter a Fahrenheit temperature: 212 212.00 Fahrenheit degrees is 100.00 Celsius degrees. Fahrenheit to Celsius Celsius to Fahrenheit Quit Please select one of the above: 2 Please enter a Celsius temperature: 0 0. 00.Celsius degrees is 32.00 Fahrenheit degrees. Fahrenheit to Celsius Celsius to Fahrenheit Quit Please select one of the above: 4 Please enter a valid choice. Fahrenheit to Celsius Celsius to Fahrenheit Quit Please select one of the above: 3Explanation / Answer
#include<iostream>
#include<conio.h>
#include<iomanip>
using namespace std;
double FahrToCel(double fahr);
double CelToFahr(double celsius);
int main()
{
cout << "Menu" << endl;
cout << "1 . Convert Fahrenheit to Celsius" << endl;
cout << "2 . Convert Celsius to Fahrenheit" << endl;
cout << "3 . Quit" << endl;
cout << "Enter your choice:" ;
int choice = 0;
cin >> choice;
//cases
switch(choice)
{
case 1:
{
cout << "Enter temperature in Fahrenheit ";
double fahr = 0.0;
cin >> fahr;
double celsius = FahrToCel( fahr );// function call
cout << " " << fahr << (char)248 << " Fahrenheit is " << fixed << setprecision(2) //decmal upto 2
<< celsius << (char)248 << " Celsius" << endl;
break;
}
case 2:
{
cout << "Enter temperature in Celsius ";
double celsius = 0.0;
cin >> celsius;
double fahr = CelToFahr( celsius );
cout << " " << celsius << (char)248 << " celsius is " << fixed << setprecision(2)
<< fahr << (char)248 << " Fahrenheit" << endl;
break;
}
case 3:
{
cout <<"Ended" << endl;
cout << " Press any key to continue...";
getch();
}
}
return 0;
}
double FahrToCel (double fahr)
{
return (5.0/9.0)*(fahr -32.0);;
}
double CelToFahr( double celsius )
{
return (celsius*9.0/5.0)+32.0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.