C++ Program 3 - Write a “Temperature Conversion” program. Declare choice, tempIn
ID: 3586540 • Letter: C
Question
C++
Program 3 - Write a “Temperature Conversion” program.
Declare choice, tempIn, tempOut variables
Prompt the user with the messages to choose: 1) Centigrade to Fahrenheit, 2) Fahrenheit to centigrade.
Prompt the user for temperature value (tempIn) to convert.
Calculate new tempOut. The calculation of the new tempOUT depends on choice 1 or 2 above.
( Lookup up the C to F formula online, loop up the F to C formula online )
Print out the the F and the C temps.
Be sure to use the C and F temperature notation ASCII symbol. (look up online )
Explanation / Answer
#include <iostream>
using namespace std;
int main()
{
cout << "Temperature Conversion" << endl;
double tempIn, tempOut;
int choice;
cout<<"Enter your choice: choose: 1) Centigrade to Fahrenheit, 2) Fahrenheit to centigrade."<<endl;
cin >> choice;
cout<<"Enter the temperature value: ";
cin >> tempIn;
if(choice == 1) {
tempOut = tempIn*(9/5) + 32;
cout<<tempIn<<" C is equivalent to "<<tempOut<<" F"<<endl;
} else {
tempOut = ((tempIn - 32) * 5)/9;
cout<<tempIn<<" F is equivalent to "<<tempOut<<" C"<<endl;
}
return 0;
}
Output:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.