Question: Modify the attached C++ program to include a menu function that will ask the user if they want to convert Fahrenheit or Celsius and then
Modify the attached C++ program to include a menu function that will ask the user if they want to convert Fahrenheit or Celsius and then return an 'F', 'C', or 'Q'
#include
// This function takes temperature and a letter as input // if the letter is C then the function will convert the temperature from celcius to fahrenheit and returns it // if the letter is F then the function will convert the temperature from fahrenheit to celsius and returns it int ConvertTemp(int tempIn, char letter) { int result; if (letter == 'C' or letter == 'c') { result = 9 * (tempIn / 5) + 32; } else { result = 5 * ((tempIn - 32)) / 9; } return result; }
int main () { char letter; // Place to store input letter int tempIn; // Temperature to be converted
// Printing menu on screen cout << "Input Menu" << endl << endl; cout << "F: Convert from Fahrenheit to Celsius" << endl; cout << "C: Convert from Celsius to Fahrenheit" << endl; cout << "Q: Quit" << endl << endl; cout << "Type a C, F, or Q; then press return." << endl;
// taking input letter from user cin >> letter;
// checking the condition if letter is not Q, if the letter is Q then loop will stop while (letter != 'Q' and letter != 'q') {
cout << " Type an integer number, and press return." << endl; cin >> tempIn;
if (letter == 'F' or letter == 'f') cout << " Fahrenheit to Celsius" << endl; else cout << " Celsius to Fahrenheit" << endl;
cout << "Temperature to convert: " << tempIn << endl; cout << "Converted temperature: ";
// using function ConvertTemp to convert the temperature as chosen by user cout << ConvertTemp(tempIn, letter) << endl << endl;
cout << "Type a C, F, or Q; then press return." << endl;
cin >> letter;
} return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
