C++ #1 Design, create, and test a program which converts degrees Fahrenheit to d
ID: 3558118 • Letter: C
Question
C++
#1 Design, create, and test a program which converts degrees Fahrenheit to degrees Centigrade (Celsius). The program must contain one main program and 3 functions: F2C() and C2F() and instructions(). The user will be asked to enter a numeric code to determine the operation. If the input code = 1, then convert F to C, if the code = 2, then convert C to F, if the input code = 3, then display instructions, and if the code = 4, then quit. The program should be in a "loop" that repeatedly performs conversions until the user quits, then the program stops. Display the instructions one time when the program starts (or whenever the user enters code = 3). Keep inputs and outputs (except for instructions) in the main program. Use F2C() and C2F() to perform conversion only.
Here is a sample output
Explanation / Answer
*
Design, create, and test a program which converts degrees Fahrenheit to degrees Centigrade (Celsius).
The program must contain one main program and 3 functions: F2C() and C2F() and instructions().
The user will be asked to enter a numeric code to determine the operation.
If the input code = 1, then convert F to C,
if the code = 2, then convert C to F,
if the input code = 3, then display instructions,
and if the code = 4, then quit.
The program should be in a "loop" that repeatedly performs conversions until the user quits,
then the program stops.
Display the instructions one time when the program starts (or whenever the user enters code = 3).
Keep inputs and outputs (except for instructions) in the main program.
Use F2C() and C2F() to perform conversion only.
*/
#include<iostream>
//#include<cstdlib>
using namespace std;
//prototype
double F2C(double );
double C2F(double );
void instructions();
int main(){
//set precision for decimal to 1
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(1);
int code;
double F,C;
instructions();
while(true){
cout<<"Enter code > ";
cin>>code;
switch(code){
case 1:// FtoC
cout<<"Enter degrees in Fahrenheit > ";
cin>>F;
C=F2C(F);
cout<<C<<" degrees Centigrade ";
break;
case 2://CtoF
cout<<"Enter degrees in Centigrade > ";
cin>>C;
F=F2C(C);
cout<<F<<" degrees Fahrenheit ";
break;
case 3://display instructions
instructions();
break;
case 4://quit
// system("pause");
cout<<"Press any key to continue . . .";
cin.get();
return 0;
break;
default:
cout<<"Invalid input entered.";
}//end switch
}//end while
//system("pause");
cout<<"Press any key to continue . . .";
cin.get();
return 0;
}
double F2C(double F){
double C = (5.0/9.0)*(F-32);
return C;
}
double C2F(double C){
double F=(9.0/5.0)*C+ 32;
return F;
}
void instructions(){//displays instructions
cout<<"This program converts temperature readings from Centigrade to Fahrenheit. "
<<"Please enter the numeric code to determine the operation. "
<<"Code = 1 Convert Fahrenheit to Centigrade "
<<"Code = 2 Convert Centigrade to Fahrenheit "
<<"Code = 3 Display Instructions "
<<"Code = 4 Quit ";
return;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.