Simple Fahrenheit to Celsius Conversion program in C++ -Contains a user-interfac
ID: 3769839 • Letter: S
Question
Simple Fahrenheit to Celsius Conversion program in C++
-Contains a user-interface function which requests the user to enter the maximum temperature as an int.
-If the maximum temperature entered is not an integer, the program must display an error message and prompt the user to re-enter the temperature.
-If the maximum temperature entered is less than or equal to 0, the program must display an error message and prompt the user to re-enter the temperature.
-Contains a function to round up the maximum temperature to the next multiple of 5 (For example 90 will remain 90, but 91 will become 95)
Contains a print function which uses a while loop to generate a table starting from 0 F to the maximum temperature in increments of 5 F
-Contains a function called convertFtoC with the following prototype:
// Uses the formula: C = (F - 32) * (5 / 9)
-The table output must be formatted.
-A sample output of your program is shown below. Columns for Celsius must have two decimal places and must be right aligned.
Example is shown below:
<Print a brief message to the user describing your program>
Please enter a maximum temperature in Fahrenheit (F): 93
Explanation / Answer
#include <iostream>
#include <cctype>
using namespace std;
int main()
{
int temp, tempCon;
char unit;
cout << "Please enter the temperature and measurement system (c or f): ";
cin >> temp;
cin >> unit;
if ( isupper(unit) )
{
unit = tolower(unit);
}
if (unit == 'f')
{
temp = (temp - 32) / 9.0 * 5.0;
cout << temp << " degrees Celsius ";
}
else if (unit == 'c')
{
temp = 9.0 / 5.0 * temp + 32;
cout << temp << " degrees Fahrenheit ";
}
else
{
cout << "Sorry that unit of measure isn't recognized around here. ";
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.