Hi guys, i was wondering about something here in this practice problem that i semi-completed i believe. it's from the book Jumping into c++ chapter 6 functions, question 1.
in the code below, i was wondering if there is a way to make a function that prints something. i wanted to make a function for
Code:
cout << " PAUSE MENU " << endl; cout << " 0. Resume Game " << endl;
cout << " 1. Commands " << endl;
cout << " 2. Controller Setup " << endl;
cout << " 3. Bottles of Beer " << endl;
cout << " 4. Quit " << endl;
cout << " What is your Choice - ";
cin >> userinput;
so i wouldn't have to retype it again in the loop, i would just call the function. but it seems whatever i try it doesn't display the text. i've tried making a function with no return time like this " Void Pausemenu(); " but that just goes blank.
thanks for any help or advice thanks.
Code:
#include <iostream>
using namespace std;
//This function displays different results based on the users input
int menu(int menuchoice);
int main()
{
//Main variable that accepts the userinput
int userinput;
cout << " PAUSE MENU " << endl;
cout << " 0. Resume Game " << endl;
cout << " 1. Commands " << endl;
cout << " 2. Controller Setup " << endl;
cout << " 3. Bottles of Beer " << endl;
cout << " 4. Quit " << endl;
cout << " What is your Choice - ";
cin >> userinput;
menu(userinput);
/*This checks whether the user entered a number
Greater than 4 or less than 0 and loops */
while( userinput < 0 || userinput > 4 )
{
cout << " \nPAUSE MENU " << endl;
cout << " 0. Resume Game " << endl;
cout << " 1. Commands " << endl;
cout << " 2. Controller Setup " << endl;
cout << " 3. Bottles of Beer " << endl;
cout << " 4. Quit " << endl;
cout << " What is your Choice - ";
cin >> userinput;
menu(userinput);
}
}
int menu(int menuchoice)
{
if ( menuchoice == 0 )
{
cout << " Game resumes and you win ";
}
else if ( menuchoice == 1 )
{
cout << " x = shoot, y = jump ";
}
else if ( menuchoice == 2 )
{
cout << " Don't know what to put here ";
}
else if ( menuchoice == 3 )
{
int beercount = 99;
while ( beercount > 0 )
{
cout << "\n" << beercount << " bottles of beer on the wall,\n" << beercount << " bottles of beer. " << endl;
beercount--;
if ( beercount > 0)
{
cout << "Take one down, pass it around, \n" << beercount << " bottles of beer on the wall... " << endl;
}
else
{
cout << "Take one down, pass it around, \n";
cout << "\nNo more bottles of beer on the wall, no more bottles of beer " << endl;
cout << "Go to the store and buy some more, 99 bottles of beer on the wall... " << endl;
}
}
}
else if ( menuchoice == 4 )
{
cout << " Game Over!!!! ";
}
return menuchoice;
}
Thanks in advance.