Program stops execution after input

I have been trying to develop a C++ Nibble Guess game. I can't figure out what is going wrong. Here's the code:

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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;

int main ()
{
    
    
  int which;
  int num;
  int guess;
  int lives = 5; 
  
  which = rand() % 17;
  switch (which) 
  {
         case 1:
              num = 0000;
              break;
         case 2:
              num = 0001;
              break;
         case 3:
              num = 0011;
              break;
         case 4:
              num = 0111;
              break;
         case 5: 
              num = 1111;
              break;
         case 6:
              num = 1110;
              break;
         case 7:
              num = 1100;
              break;
         case 8:
              num = 1000;
              break;
         case 9:
              num = 1001;
              break;
         case 10:
              num = 1011;
              break;
         case 11:
              num = 1101;
              break;
         case 12:
              num = 0110;
              break;
         case 13:
              num = 0100;
              break;
         case 14:
              num = 0010;
              break;
         case 15:
              num = 0101;
              break; 
         case 16:
              num = 1010;
              break;
              }
              cout << "Please guess a nibble: ";
              cin >> guess;
              if (guess == num)
              {
                        int yn;
                        cout << "Correct! Would you like to play again? (1/2): ";
                        cin >> yn;
                        switch (yn) 
                        { 
                               case 1:
                                    main();
                                    break;
                               case 2:
                                    return 0;
                                    }
                                    }
              else {
                   if (lives == 0)
                   {
                             int again;
                             cout << "Your lives are up. Would you like to play again? (1/2): ";
                             switch (again) 
                        { 
                               case 1:
                                    main();
                                    break;
                               case 2:
                                    return 0;
                                    }
                   cout << "Sorry, that is not right. Try again.";
                   lives = lives - 1;
                   main();
                   }
                   return 0;
                   }
                   system("PAUSE");
}
if lives == 0 "game over try again" ok but what if lives is not 0 ? you write return 0 at line 101 this line breaks the program and stops it

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

		if (lives == 0)
		{
			int again;
			cout << "Your lives are up. Would you like to play again? (1/2): ";
			switch (again) 
			{ 
			case 1:
				main();
				break;
			case 2:
				return 0;
			}
			cout << "Sorry, that is not right. Try again.";
			lives = lives - 1;
			main();
		} 
// what if lives is not 0 ? you break the program here
		return 0;
Are you aware that num = 0101; is octal and num will have 65?

Avoid calling main() inside main(), you could easily solve it with a loop
thanks guys it runs now
Topic archived. No new replies allowed.