Repeat then ends??

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
int recieveFirst()
{
	char input[5] = {"\0"};
	cin.get(input , 5);
	
	if(isalpha(input[0]))
	{
		
		if(input[0] == 'h' || input[0] == 'H')
		{
			help();
		}
		else if(input[0] == 'n' || input[0] == 'N')
		{
			startNewGame();
			return 1;
		}
		else
		{
			cout << "Not a recognized response.  Please type 'H' for help or 'N' to start a new game.";
			recieveFirst();
		}
		
	}
	else
	{
		cout << "Not a recognized response.  Please type 'H' for help or 'N' to start a new game.";
		return 0;
	}
	return 1;
}	


On line 21, I want to start the function again, so that the user can input the correct respone. The output rather looks something like this:


Not a recognized response. Please type 'H' for help or 'N' to start a new game.
Not a recognized response. Please type 'H' for help or 'N' to start a new game.


The second line, is within the else statement for the first if.

after those two it ends!

Why is this happening?
Why does it not wait for the input when the function is called again?

EDIT: This obviously only happens when the user does not enter an N or H.
Last edited on
Line 4 use

 
cin>>input[0];

instead of cin.get()
Last edited on
Topic archived. No new replies allowed.