Write a program that first asks the user which Temperature scale conversion woul
ID: 3629552 • Letter: W
Question
Write a program that first asks the user which Temperature scale conversion would he like to perform:1. Convert F to C
2. Convert C to F
What is your choice?
Then it asks the user for input for three real number variables: start_temp, end_temp, temp_incr. It will then produce a two column Fahrenheit to Celsius table or a two column Celsius to Fahrenheit table, depending on the choice. For choice 1, The first column should be labeled Fahrenheit and the first value the Fahrenheit column is start_temp. The second column should be labeled Celsius, and its value is calculated from the values in the Fahrenheit column using the formula C = (5.0/9.0)*(F – 32.0). For choice 2, the table will show the Celsius column first, Fahrenheit column second, and use the formula F = 9.0/5.0 * C + 32.0
Write and use functions called calcCelsius (is passed the Fahrenheit temp and returns the Celsius temp) and calcFahrenheit(is passed the Celsius temp and returns the Fahrenheit temp).
The values for the temps in the first column will be incremented by temp_incr, and end when the table value would exceed the end_temp value. Display all values with 2 decimal of accuracy, justified and aligned.
Explanation / Answer
please rate - thanks
with the functions as requested
#include<iostream>
#include<iomanip>
using namespace std;
double calcCelsius(double);
double calcFahrenheit(double);
int main()
{
int choice;
double start_temp, end_temp, temp_incr;
cout<<"1. Convert F to C "<<endl;
cout<<"2. Convert C to F "<<endl;
cout<<"What is your choice? " <<endl;
cin>>choice;
cout<<"Enter starting temperature: ";
cin>>start_temp;
cout<<"Enter ending temperature: ";
cin>>end_temp;
cout<<"Enter temperature increment: ";
cin>>temp_incr;
if(choice==1)
{cout << "Fahrenheit Celsius"<<endl;
cout<< "---------- -------"<<endl;
while(start_temp<=end_temp)
{cout<<setw(10)<<setprecision(2)<<fixed<<start_temp<<
setw(10)<<setprecision(2)<<fixed<<calcCelsius(start_temp)<<endl;
start_temp+=temp_incr;
}
}
else if(choice==2)
{cout << "Celsius Fahrenheit"<<endl;
cout << "------- ----------"<<endl;
while(start_temp<=end_temp)
{cout<<setw(7)<<setprecision(2)<<fixed<<start_temp<<
setw(13)<<setprecision(2)<<fixed<<calcFahrenheit(start_temp)<<endl;
start_temp+=temp_incr;
}
}
else
cout<<"invalid entry-program aborting ";
system("pause");
return 0;
}
double calcCelsius(double t)
{return 5./9.*(t-32.);
}
double calcFahrenheit(double t)
{return 9./5.*t+32.;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.