Using C+++ Program. You are going to convert temperatures in this program. You w
ID: 3846799 • Letter: U
Question
Using C+++ Program.
You are going to convert temperatures in this program. You will give the user the choice of converting Fahrenheit to Celsius or Celsius to Fahrenheit. With the correct answer you will also display the number entered. The user should have the option to convert as many temperatures as they want. Use functions and a menu (also a function) and, assume they will convert at least one temperature. When finished upload and submit the zipped project.
the formulas are:
centigrade = (fahrenheit - 32) * 5/9
fahrenheit = centigrade * 9/5 + 32
Trivia: the brains behind:
Anders Celsius, Swedish physicist and astronomer, 1701 - 1744
Gabriel Fahrenheit, German physicist, 1686 - 1736, inventor of the thermometer
how did they choose the ranges?
CELSIUS:
range of 100 steps,
0 degree Centigrade = freezing point of water,
100 degree Centigrade = boiling point of water
FAHRENHEIT:
range of 180 steps,
32 degree Fahrenheit = freezing point of water,
100 degree Fahrenheit = body temperature of a person (not very accurate...),
212 degree Fahrenheit = boiling point of water
Explanation / Answer
#include <iostream>
using namespace std;
float convertToFah(float ce)
{
return ce*9/5+32;
}
float convertToCel(float fah)
{
return (fah-32)*5/9;
}
void menu()
{
int choice=0;
float value;
cout << "Enter 1 to convert from Fahrenheit to Celsius and 2 to convert Celsius to Fahrenheit"<<endl;
cin >> choice;
switch(choice)
{
case 1 : cout<< "Enter the value in Fahrenheit : ";
cin >> value;
cout << "The value in celsius is "<<convertToCel(value)<<endl;
break;
case 2 : cout<< "Enter the value in Celsius : ";
cin >> value;
cout << "The value in Fahrenheit is "<<convertToFah(value)<<endl;
break;
default : break;
}
}
int main()
{
int ch;
do {
menu();
cout << "Enter 1 to do the conversions 2 to quit : ";
cin >> ch;
}while(ch == 1);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.