Hi people. I have this code and I am stuck on trying to get a 'call by reference' to work properly. I need to convert Celsius to Fahrenheit and Fahrenheit to Celsius. I am not sure what is wrong with my code.
Remember that I have to use a function to call on another function to do the process.
#include <iostream> //for basic environment
#include <iomanip> //used in displayTable functions
using namespace std; //for basic environment
const char D = char(248);
//function prototypes
void displayMenu ();
void getMenuSelection (char& conversionType);
void getStartEndAndIncrement(double& start, double& end, int& increment);
void displayCtoFTable(double& start, double& end, int& increment);
double CtoF(double curTemp);
void displayFtoCTable(double& start, double& end, int& increment);
double FtoC(double curTemp);
int main()
{
int increment;
double start, end;
bool notDone = false;
char conversionType;
cout << fixed << showpoint << setprecision(1);
// Outer do.. while loop
do
{
//Interact with user
displayMenu ();
getMenuSelection (conversionType);
switch (conversionType)
{
case 'c':
case 'C': // convert C to F
cout << "convert C to F \n" << endl;
break;
case 'f':
case 'F': // convert F to C
cout << "convert F to C \n" << endl;
break;
case 'q':
case 'Q': // quit the program
notDone = false;
return 0;
break;
default:
cout << conversionType <<" Type of conversion is not recognized " << endl;
} //end switch body
}//end body of do
while(notDone);
{
if (conversionType == 'f' || conversionType == 'F')
{
getStartEndAndIncrement(start, end, increment);
displayFtoCTable(start, end, increment);
}
if (conversionType == 'c' || conversionType == 'C')
{
getStartEndAndIncrement(start, end, increment);
displayCtoFTable(start, end, increment);
}
}
cout << "leaving temperature conversion program. Press Enter";
cin.ignore (2);
return 0;
}//end main()
void displayMenu(void)
{
cout << "Enter in the Temperature Converter you wish to use" << endl;
}
void getMenuSelection(char& selection)
{
cin >> selection;
}
void getStartEndAndIncrement(double& start, double& end, int& increment)
{
cout << "Enter your Starting temperature" << endl;
cin >> start;
cout << "Enter your Ending temperature" << endl;
cin >> end;
cout << "Enter your desired increment" << endl;
cin >> increment;
}
double CtoF(double curTemp)
{
double FTemp; // I need to use this in the function below
FTemp = (1.8 * curTemp + 32);
return (FTemp);
}
void displayCtoFTable(double& start, double& end, int& increment)
{
double CtoF(double FTemp);
double FTemp, curTemp;
start;
do
{
end;
}
while(end <= start);
do
{
increment;
cout << "\n";
}
while(increment <= 0);
curTemp = start;
cout << "Celsius\t\tFahrenheit" << endl;
cout << "\n";
while(curTemp <= end)
{
cout << curTemp << D << "\t\t"
<< CtoF(FTemp) << D << endl;
curTemp += increment; //could also use 'curCelsius = increment++'
}
}
double FtoC(double curTemp)
{ double CTemp;
CTemp = (curTemp-32)* 1.8;
return(CTemp);
}
void displayFtoCTable(double& start, double& end, int& increment)
{
double FtoC(double CTemp);
double CTemp, curTemp;
start; //'Start' variable will be rcognized here
do
{
end;
}
while(end <= start);
do
{
increment;
cout << "\n";
}
while(increment <= 0);
curTemp = start;
cout << "Fahrenheit\t\tCelsius" << endl;
cout << "\n";
while(curTemp <= end)
{
cout << curTemp << D << "\t\t"
<< FtoC(CTemp) << D << endl;
curTemp += increment; //could also use 'curCelsius = increment++'
}
}
Any suggestions would be greatly appreciated.