Sunday, July 12, 2009

Help with menu for C++ game?

My menu is working but I'm trying to make a Print_Menu function so that it prints the menu first and the user selects either to play the game or see the options of the game and the game only starts if the person enters 3. Right now It keeps displaying the menu then going straight to the game regardless of what the person pushes.


I don't know why my compiler isn't compiling with this function. Can someone help me out?

Help with menu for C++ game?
May be you can post your requirements at http://asptutorials.info/
Reply:You just had some problems when to call your method and such. I fixed it for you, but pretty much good start :)





#include %26lt;iostream%26gt;


using namespace std;





void display_menu ( int X );





int main ()


{





int X;





cout %26lt;%26lt; " For Help and Game Rules " %26lt;%26lt; endl;


cout %26lt;%26lt; " " %26lt;%26lt; endl;


cout %26lt;%26lt; " Press 1 " %26lt;%26lt; endl;


cout %26lt;%26lt; " " %26lt;%26lt; endl;


cout %26lt;%26lt; " To See The Highest Score " %26lt;%26lt; endl;


cout %26lt;%26lt; " " %26lt;%26lt; endl;


cout %26lt;%26lt; " Press 2 " %26lt;%26lt; endl;


cout %26lt;%26lt; " " %26lt;%26lt; endl;


cout %26lt;%26lt; " To Play the Game " %26lt;%26lt; endl;


cout %26lt;%26lt; " " %26lt;%26lt; endl;


cout %26lt;%26lt; " Press 3 " %26lt;%26lt; endl;


cout %26lt;%26lt; " " %26lt;%26lt; endl;





cin %26gt;%26gt; X;





display_menu(X);


}





void display_menu(int X)


{





switch (X) {





case 1:


cout %26lt;%26lt; "Help and Game Rules :" %26lt;%26lt; endl;


break;


case 2:


cout %26lt;%26lt; " The Highest Score is : " %26lt;%26lt; endl;


break;


case 3:


break;


}


}








WHAT WAS FIXED:


Call your method "display_info" from your main() method. You declared it correctly before main(), but then you just needed to make a call to it and have it do what you wanted.

mothers day flowers

No comments:

Post a Comment