Program Unresponsive

Im currently in highschool, and in a C++ Programming Class
Before the end of the year we must creates a game, and I've been working on the project. We have yet to learn the void declaration (or whatever it is when you do this "void name()" instead of "int main()") so I've gone online to look up how these work. My problem is that when I run the program, it displays the void over and over (kind of flashing text) and won't respond to any user input, so I must stop debugging.
Here's the code of the two important parts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <string>
#include <stdio.h> 

using std::cin;
using std::cout;
using std::endl;
using std::string;

//Global Vars
int mainMenuChoice = 0;

//voids
	void options();
	void mainMenu();
	void startGame();

//inizialize main
int main() 
{
	mainMenu();
	return 0;

}

and the void
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
void mainMenu()
{
	// Display Menu
	system("color 20");
	cout << "				Zombie Survival				" << endl << endl;
	cout << "Select # for choice of game" << endl << endl;
	cout << "1: New Game (Starts a brand new game)" << endl;
	cout << "2: Load Game (Loads a Previously Saved game)" << endl;
	cout << "3: Options (Selects Options)" << endl;
	cout << "4: Exit (Exits the Program)" << endl;

	// input
	switch(mainMenuChoice)
	{
	case 1:
		system("CLS");
		cout << " New Game Started ";
		system("pause");
		startGame();
		break;
	case 2:
		system("CLS");
		cout << " Function not yet Completed " << endl;
			/* 

			*/
		system("pause");
		mainMenu(); // returns to main menu
		break;
	case 3:
		system("CLS");
		options(); // brings to options
		break;
	case 4:
		system("CLS");
		exit (1);
	default:
		system("cls");
		mainMenu();
	}
	system("pause");

}


It outputs the menu over and over(the texts stays half a second and disapears, then reappears, flashing), and doesnt allow any input.
Correct me if I'm wrong, but you don't actually ever ask for any input. >_>

Because the input variable is never set, it repeatedly enters into default (as the variable is 0), which clears the screen and re-displays the menu. This happens forever.

I would highly recommend using a loop for the menu instead of recursively calling mainMenu()...the way you have it written now, it will recurse infinitely until the program runs out of stack space and dies.
Hello,

What you receive an error ?

@firix: TC said the program runs, it just doesn't do what is expected.
the problem occurs while the main menu screen displays, but yes Zhuge, I just saw i have no input, so im guessing th computer reads it and doesnt see any way the user can input so instantly chooses default for the user, bringing them back to the main menu. I cant fix it now but when im back on the right computer ill check it out. Thanks in advanced if this works
add cin >> mainMenuChoice;
after you display the menu,
Topic archived. No new replies allowed.