I am a new programmer and I am making a menu for a game I am making and something went wrong, every time I type in the the number to open the menu, it says what was in that catagory but it reshows the menu again I want it to just show the words in that catagory then have a back button to go back to the menu here is the code please help, if you can please fix it and add the back button to each catagory: #include <iostream>
using namespace std;
int main()
{
int choice;
bool gameOn = true;
while (gameOn != false){
cout << "*******************************\n";
cout << " 1 - Start the game.\n";
cout << " 2 - Story.\n";
cout << " 3 - Help.\n";
cout << " 4 - Exit.\n";
cout << " Enter your choice and press return: ";
cin >> choice;
switch (choice)
{
case 1:
cout << "game!.\n";
// rest of code here
break;
case 2:
cout << "Story.\n";
// rest of code here
break;
case 3:
cout << "help.\n";
// rest of code here
break;
case 4:
cout << "End.\n";
gameOn = false;
break;
default:
cout << "Not a Valid Choice. \n";
cout << "Choose again.\n";
cin >> choice;
break;
}
I don't see anything wrong besides lack of functionality. Your game is doing exactly what you've written.
I do see a minor problem with your default case. You're going to do the cin twice. Once after "Choose again" and then again at the top of the loop.
In each of your cases, you're going to want to call an appropriate function to handle that case. In each of those respective functions, you're going to want to implement a "submenu" which includes a "back" option.
PLEASE USE CODE TAGS (the <> formatting button) when posting code. http://v2.cplusplus.com/articles/jEywvCM9/
It makes it easier to read your code and it also makes it easier to respond to your post.
Could you tell me how to make it when I put in the code it and press one of the catagorys that it will just pull up a screen with the words on it then there is a back button that will take me back to the menu? Thanks in advanced!
What you have shown so far is text based on the console. As soon as you mention "press a back button", you're implying some kind of GUI that supports buttons. That's a different kind of program.
That's not a good strategy. Casting a char* to an int will not give you what you want in that case. You'll have to do something more complicated to convert to an integer.
Also, I would highly recommend against using conio.h because of its age and non-portability.