Program closing out after I get input

My program is a game. Two numbers are randomly generated until they match, and the player must guess where these two numbers will match. However, at line 111 after I get the player's guess, the program creates crazy numbers within the hundred-thousands range and then shuts off after it gets a match. It'd be very helpful to get some advice on this.

Thanks everybody.

Oh, and don't irk me for using Sleep. I know it's a bad thing to do but this is a just for fun assignment.
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <iostream>
#include <windows.h> // ALWAYS include when using Sleep function;
#include <ctime>

using namespace std;

int first = 5;
int second = 2;
int switchit;
int advancedfirst, advancedsecond;
int guess;


srand ( time(NULL) );

void firstnumber() // randomize first number
{
    first = rand() % 200 + 50;
}

void secondnumber() // randomize second number
{
    second = rand() % 200 + 50;
}



int advancedfirstnumber()
{
    advancedfirst = rand() % 500 + 50;
    return advancedfirst;
}



int advancedsecondnumber()
{
    advancedsecond = rand() % 500 + 50;
    return advancedsecond;
}

void advanced()
{
     system("CLS");
     //ask player to enter number guess; get number; create loop for 50-500
     int advancedguess;
     cout<<"********************************************\n\n\t\t\tADVANCED - 00000065432\n\n********************************************\n\n";
     cout<<"Welcome to Advanced difficulty. The number range has moved up from 50-200 to 50-500.";
     cout<<"I trust you have the patience for this one; it'll surely take a while.\n";
     cout<<"\n\t\t\t\tShall we begin?:";
     cout<<"\n\t\t\t";
     string begin;
     getline(cin, begin);
     if (begin == "yes" || begin == "sure" || begin == "ok" || begin == "yeah" || begin == "yea" ||
     begin == "hell yeah")
     {
           cout<<"\n\n\t\t\t\tVery well.\n";
     }
     else {
          cout<<"\n\n\t\t\t\tWell hurry up, I'll give you 20 seconds to get ready.\n";
          Sleep(5000);
          }
advancedrestart:
     cout<<"\nEnter a number between 50 and 500: ";
     cin>>advancedguess;
     cout<<"\n\n";
     do {
         // display number, two spaces, display second, two spaces
         advancedfirstnumber();
         cout<< advancedfirstnumber();
         cout<<"  ";
         advancedsecondnumber();
         cout<< advancedsecondnumber();
         cout<<"  ";
        } while (advancedfirst != advancedsecond);
     // check if the guess is equal to where the two numbers matched
     if (advancedguess == advancedfirst)
     {
                       cout<<"\n\n\t\t\t\tVery nice.\n\n";
                       cout<<"Well that's it for now, I'll be adding in another level soon.\n";
                       Sleep(2000);
                       exit (1);
     }
     
     else {
          cout<<"\n\n\t\t\t\tThat is incorrect.";
          Sleep(5000);
          cout<<"\n\n\t\t\t\t\t ...";
          goto advancedrestart;
          }
}
     
        
        

int main()
{
    cout<<"In this game, random numbers will be generated until those two numbers match.\n\n";
    Sleep(4000);
    cout<<"You will guess which number the two will match at.\n\n";
    Sleep(4000);
    cout<<"If you get it wrong, it will restart.\n";
    cout<<"Get ready.\n\n";
    Sleep(5000);
    cout<<"3.. "; Sleep(400); cout<<"2.. "; Sleep(400); cout<<"1.. "; Sleep(400); cout<<"go!\n\n\n"; // 3.. 2.. 1.. go!
 restart:
    cout<<"Guess a number between 50 and 200: ";
    cin >> guess;
    cout<<"Press enter.\n";
    cin.get();
    
    while (first != second) 
    {

          first = rand() % 200 + 50;
          cout<< first;
          cout<<"  ";
          second = rand() % 200 + 50;
          cout<<"  ";
          cout<< second;
    } 
    
    if (guess == first)
         {
              if (guess == second)
options:
              cout<<"Nice.\n\n\n\n\n\n\t\t\t\t";
              cout<<"1/ Restart\n\t\t\t\t";
              cout<<"2/ Move on to Advanced difficulty\n\t\t\t\t";
              cout<<"3/ Exit.\n";
              cin>>switchit;
              switch (switchit)
              {
                     case 1:
                             goto restart;
                             break;
                     case 2:
                             advanced();
                             break;
                     case 3:
                             exit (1);
                             break;
                     default:
                             cout<<"You had to enter 1-3, please do so.\n";
                             goto options;
                             break;
              }
         }
    else if (!guess == first)
         {
         goto restart;
         }
}
Last edited on
SOLVED.
Topic archived. No new replies allowed.