Write a program that gets starting and ending temperatures in °C and a step size
ID: 3623227 • Letter: W
Question
Write a program that gets starting and ending temperatures in °C and a step size (also in °C) from the user and then calls a function to print a two-column table of temperatures in °C and °F such as that shown below:Enter a starting temperature (°C):
0
Enter an ending temperature (> 0.00):
50
Enter a positive step size:
10
°C °F
---- ----
0.0 32.0
10.0 50.0
20.0 68.0
30.0 86.0
40.0 104.0
50.0 122.0
Repeat program (Y/N)? y
Enter a starting temperature (°C):
.1
Enter an ending temperature (> 0.1000):
50
Enter a positive step size:
10
°C °F
---- ----
0.1 32.2
10.1 50.2
20.1 68.2
30.1 86.2
40.1 104.2
Repeat program (Y/N)? y
Enter a starting temperature (°C):
10
Enter an ending temperature (> 10.00):
5
Enter an ending temperature (> 10.00):
15
Enter a positive step size:
-1
Enter a positive step size:
1
°C °F
---- ----
10.0 50.0
11.0 51.8
12.0 53.6
13.0 55.4
14.0 57.2
15.0 59.0
Repeat program (Y/N)? n
Note that the program should not allow the ending temperature to be less than or equal to the starting temperature, and the step size must be a positive number. The program should repeat until the user decides to quit. You should be able to produce output identical to that shown above.
Explanation / Answer
please rate - thanks
#include <iostream>
#include<iomanip>
using namespace std;
int main()
{double start, stop,i,step;
char choice;
do
{
cout<<"Enter a starting temperature ("<<char(248)<<"C): ";
cin>>start;
cout<<"Enter an ending temperature (> 0.00): ";
cin>>stop;
while(stop<=start)
{
cout<<"Enter an ending temperature (> 0.00): ";
cin>>stop;
}
cout<<"Enter a positive step size: ";
cin>>step;
while(step<=0)
{
cout<<"Enter a positive step size: ";
cin>>step;
}
cout<<char(248)<<"C "<<char(248)<<"F ";
cout<<"----- ----- ";
for(i=start;i<=stop;i+=step)
cout<<setprecision(1)<<fixed<<i<<" "<<1.8*i+32.<<endl;
cout<<endl;
cout<<"Repeat program (Y/N)? ";
cin>>choice;
}while(choice=='Y'||choice=='y');
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.