//This function displays a brief overview explaining the program to the user
void programOverview ()
{
cout << "This program will convert a temperature reading provided in" << endl;
cout << "either Fahrenheit or Celsius to the other measurement scale." << endl;
}
//This function requires the user to enter the temperature scale to be used
char getScale ()
{
char scale;
cout << "Enter the letter of the temperature scale that will be used:" << endl;
cout << "F = Fahrenheit; C = Celsius)" << endl;
cin >> scale;
return scale;
}
//This function requires the user to enter the temperature reading in degrees
double getDegree ()
{
double degree;
cout << "Enter your temperature reading in degrees:" << endl;
cin >> degree;
return degree;
}
//This function converts a Fahrenheit temperature to Celsius
double convertFtoC (double Ftemp)
{
double Ctemp;
Ctemp = (Ftemp - 32) / 1.8;
return Ctemp;
}
//This function converts a Celsius temperature to Fahrenheit
double convertCtoF (double Ctemp)
{
double Ftemp;
Ftemp = 1.8 * Ctemp + 32;
return Ftemp;
}
#include <iostream>
#include <iomanip>
usingnamespace std;
void programOverview ();
void callProg ();
void FtoC ();
void CtoF ();
void getResults (double, double);
int main ()
{
programOverview ();
callProg();
return 0;
}
//This function displays a brief overview explaining the program to the user
void programOverview ()
{
cout << "This program will convert a temperature reading provided in" << endl;
cout << "either Fahrenheit or Celsius to the other measurement scale." << endl;
}
//This function requires the user to enter the temperature scale to be used
void callProg()
{
int scale;
cout << "Enter the letter of the temperature scale that will be used:" << endl;
cout << "1) Fahrenheit 2) = Celsius)" << endl;
cin >> scale;
switch (scale)
{
case 1 : FtoC();
case 2 : CtoF();
default : cout << "Nonvalid selection!" << endl;
}
}
//This function requires the user to enter the temperature reading in degrees
double getDegree ()
{
double degree;
cout << "Enter your temperature reading in degrees:" << endl;
cin >> degree;
return degree;
}
//This function converts a Fahrenheit temperature to Celsius
void FtoC ()
{
double Ctemp, Ftemp;
Ftemp = getDegree();
Ctemp = (Ftemp - 32) / 1.8;
getResults(Ftemp, Ctemp);
}
//This function converts a Celsius temperature to Fahrenheit
void CtoF ()
{
double Ftemp, Ctemp;
Ctemp = getDegree();
Ftemp = Ctemp*1.8 + 32;
getResults(Ftemp, Ctemp);
}
//This function displays the results
void getResults (double Ftemp, double Ctemp)
{
cout << "Your temperature reading converts as follows:" << endl;
cout << setprecision (4);
cout << "Fahrenheit:" << Ftemp << endl;
cout << setprecision (4);
cout << "Celsius:" << Ctemp << endl;
}
I would do something like this, brief up the functions, called a switch statement instead of asking for char. I would make the source even simpler though.