I need help with C++

I'm building a converter (fahrenheit -> celsius or Celsius -> fahrenhhiet) that will make the user type 3 integer (starting temperature, an ending temperature, and an increment)


I have this problem: the variable ch is being used without being initialized.


#include <iostream>
#include <iomanip>
using namespace std;

void displayMenu(); //prototype
char getMenuSelection(); //prototype
void displayTable(int start, int end, int increment, char ch); //prototype
void getStartEndAndIncrement(int &start, int &end, int &increment);// prototype
double CtoF(double C); // convert to Celsius to fahrenheit.
double FtoC(double F); // convert to fahrenheit to Celsius.
int main()
{
char selection;
int startTemp = 0, endTemp = 0, incrementTemp = 0;
int start = 0, end = 0, increment = 0;
char ch;
selection = getMenuSelection();
while(selection!= 'Q')
{


getStartEndAndIncrement(startTemp, endTemp, incrementTemp);
displayTable(start, end, increment, ch);
selection = getMenuSelection();

}

return 0;
}//end main

void displayMenu()
{
cout << endl;
cout << "Enter F to convert Fahrenheit to Celsius: " << endl;
cout << "Enter C to convert Celsius to Fahrenheit: " << endl;
cout << "Enter Q to quit program" << endl;


}// displayMenu;
char getMenuSelection()
{
char option;
do{
displayMenu(); // callling displayMenu()
cin >> option;
option = toupper(option);
switch(option)
{
case 'C':
case 'F':
case 'Q':
break;
default:
cout << "Invalid input! Try again" << endl;




}//end switch

return option;
}while(option != 'C' && option != 'F' && option != 'Q'); // end do/ while loop


}// end getMenuSelection()
void getStartEndAndIncrement(int &start, int &end, int &increment)
{

cout << "Enter starting temperature: ";
cin >> start;
cout << "Enter ending temperature: ";
cin >> end;
cout << "Enter incrementing temperature: ";
cin >> increment;
}

void displayTable(int start, int end, int increment, char ch)
{
double convertedTemp;
cout << fixed << showpoint << setprecision(1) << right;
if(ch == 'C')
{
cout << setw(1) << (char)248 << 'C' << setw(1) << (char)248 << 'F' << endl;

}
else
{
cout << setw(1) << (char)248 << 'F' << setw(1) << (char)248 << 'C' << endl;

}

for(int temp = start; temp <= end; temp += increment)
{
if(ch == 'C')
{
convertedTemp = CtoF(temp);

}
else
{
convertedTemp = FtoC(temp);
}

cout << setw(1) << temp << setw(1) << convertedTemp << endl;


}

}
double CtoF(double C)
{
return 9.0/5.0 * C + 32;

}

double FtoC(double F)
{
return 5.0/9.0 * F - 32;

}



can someone help me finish this program???
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
int main()
{
char selection;
int startTemp = 0, endTemp = 0, incrementTemp = 0;
int start = 0, end = 0, increment = 0;
char ch; //*******DO INITIALIZE IT by any mean, either take as input****
selection = getMenuSelection();
while(selection!= 'Q')
{


getStartEndAndIncrement(startTemp, endTemp, incrementTemp);
displayTable(start, end, increment, ch);
selection = getMenuSelection();

}


You are passing ch without initializing it.
thanks for the reply BTW.

sorry i dont really get it...... could u give me some example or explain to me what exactly i need to put....

ps

i know that char ch is the one that i need to initialize but i don't know how to initialize it. I'm knew on this so sorry.

My brain is exploding


ps. Nevermind mind. i'm done ^.^)_V..
Last edited on
Topic archived. No new replies allowed.