Write a program in C++ that converts Celsius temperatures to Fahrenheit temperat
ID: 3595614 • Letter: W
Question
Write a program in C++ that converts Celsius temperatures to Fahrenheit temperatures. The formula is F=9/5*C+32
F is the Fahrenheit temperature, and C is the Celsius temperature.
Your program should prompt the user for a lower and upper range of temperatures in Celsius. Then use a loop to display a table of the Celsius temperatures and their Fahrenheit equivalents. within the range of values.
INPUT VALIDATION: Ensure the second number is greater than the first number.
This is different than the one that had already been answered on this website.
Explanation / Answer
#include <iostream>
using namespace std;
int main()
{
int lower, upper; //declaring variables for lower and upper bounds
cout << "Enter the lower range temperatures in Celsius: " << endl;
cin >> lower;//reading lower bound
cout << "Enter the upper range temperatures in Celsius: " << endl;
cin >> upper; //reading upper bound
while(upper <= lower) { //checking whether upper bound is less than or equals to lower
cout << "Invalid Input. Must be greater than lower range. Enter the upper range temperatures in Celsius: " << endl;
cin >> upper; //if upper is less than or equals to lower then reading again the upper value
}
cout<<"Celsius Fahrenheit"<<endl;
for(int celsius=lower; celsius<=upper;celsius++) { //looping to display fromlower to upper bound
cout<<celsius<<" "<<(celsius*(9/(double)5) + 32)<<endl; //display celcius and correcponding faherenheit values
}
return 0;
}
Output:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.