Hello, this question is for people that are fluent in c++. Note: we don\'t use p
ID: 669021 • Letter: H
Question
Hello, this question is for people that are fluent in c++. Note: we don't use print
In this case project, you will enhance the temperature conversion program. This time, you will ask if the user would
like to convert from Fahrenheit to Celsius, or from Celsius to Fahrenheit, and then perform the appropriate calculations based on the input. Also, change the display to format the floating-output as a whole number (rather than using the static_cast operator). Make necessary modifications in variable declarations and names. Use the final selection
path (whether in an if statement and switch statement) to output a message if the user did not choose a valid conversion type. Use an assert statement to verify that the user enters a value above absolute zero in Celsius (–273 degrees).
Finally, use any type of loop to make the program work several times, until the user ends the loop.
Thank you very much !
Explanation / Answer
#include <iostream>
using namespace std;
int main()
{
int ftemp;
int ctemp;
int select = 0;
while(1){
cout << "Please select from the following: " << endl;
cout << "1) Fahrenheit-to-Celsius" << endl;
cout << "2) Celsius-to-Fahrenheit" << endl << endl;
cout << "Enter: ";
cin >> select;
if (select == 1)
{
cout << " Enter temperature in Fahrenheit to convert to degrees Celsius: ";
cin >> ftemp;
ctemp = (ftemp-32) * 5 / 9;
cout << "Equivalent in Celsius is: " << ctemp << endl;
}
else if (select == 2)
{
cout <<" Enter temperature in Celsius to convert to degrees Fahrenheit: ";
cin >> ctemp;
if(ctemp> -273){
ftemp = ctemp*9/5 + 32;
cout << "Equivalent in Fahrenheit is: " << ftemp << endl;
}
else{
cout <<" Please enter valid Celsius(>-273)";
}
}
else
cout << "Valid options 1 or 2." << endl;
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.