#include <iostream> #include <stdlib.h> using namespace std; int main() { double
ID: 3633576 • Letter: #
Question
#include <iostream>#include <stdlib.h>
using namespace std;
int main()
{
double ftemp;
double ctemp;
int select = -1;
while (select ==-1)
{
cout << "Please select from the following (0 to quit): " << 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;
ftemp = ctemp*9/5 + 32;
cout << "Equivalent in Fahrenheit is: " << ftemp << endl;
}
else if (select == 0)
exit(0);
else
cout << "Valid options 1 or 2." << endl;
select = -1;
}
return 0;
}
Explanation / Answer
start variable ctemp,ftemp; while(select!=-1) select your choice 1) Fahrenheit-to-Celsius 2) Celsius-to-Fahrenheit end while if(select==1) calculate Fahrenheit-to-Celsius conversion take temperature in ftemp as fahrenheit ctemp = (ftemp-32) * 5 / 9; enf if if(select==1) calculate Fahrenheit-to-Celsius conversion take temperature in ctemp as celcius ftemp = ctemp*9/5 + 32; end if end
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.