function

int menu()
{
char letter; // Place to store input letter
int tempIn; // Temperature to be converted

cout << "Input Menu" << endl << endl;
cout << "F: Convert from Fahrenheit to Celsius" << endl;
cout << "C: Convert from Celsius to Fahrenheit" << endl;
cout << "Q: Quit" << endl;
cout << "Type a C, F, or Q; then press enter." << endl;

cin >> letter;
while (letter != 'Q')
{
cout << " Type an integer number, and press return."
<< endl;
cin >> tempIn;

if (letter == 'F')
cout << "Fahrenheit to Celsius" << endl;
else
cout << "Celsius to Fahrenheit" << endl;
cout << "Temperature to convert: " << tempIn << endl;
cout << "Converted temperature: "
<< ConvertedTemp(tempIn, letter) << endl << endl;
cout << "Type a C, F, or Q; then press return." << endl;

cin >> letter;
}
return;
}

// *****************************************************

int ConvertedTemp(int f,int c)
{
// ConvertedTemp() is used to convert temperatures from
// Fahrenheit to Celsius or from Celsius to Fahrenheit
// depending on whether the user entered an F or a C.
// C = (9 * tempIn / 5) + 32
// F = 5 * (tempIn - 32) / 9;
int fa,ce;
int tempIn;
char s,t;
char letter;

if (letter == 't')
ce = (9 * tempIn / 5) + 32;
else if(letter == 's')
fa = 5 * (tempIn - 32) / 9;
else if (letter == 'q')
cout<<"Quiting"<<endl;

}





i wrote this program up but now i need to change it,change so that the menu is displayed isstead of being printed by the main()function.it should be named displayMenu().
Um, that's pretty simple if I understand you correctly...

Take a look at this example:
1
2
3
4
5
6
7
8
9
10
void Show_Menu()
{


//Display Menu Here


//Direct it to another function
PlayGame();
}


Simple,right? Just put your menu in a function, and call it in your main.
Also, just a friendly-reminder, please use code tags when you post, it makes everything nicer.

-Code Assassin
Last edited on
Topic archived. No new replies allowed.