Gambling Age Restriction Code

Hey all,
I am writing a gambling dice code but I just realized before the game starts I have to ensure that the user is 21 or above. I am not sure how to do this without messing up my other code. I just wanted to do a simple break/continue statement but it is giving me an error.

Again this code is just the beginning of my whole program.
1
2
3
4
5
6
7
8
9
  int main() {
    
    int age;
    cout << "Please enter your age:";
    cin >> age;
    if (age>=21)
        continue;
    else
        break;
Why don't you just use the if statement and put all your code in main inside the if (age>=21) and then after your closing brackets have your else with a cout telling the user there to young? Something like:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
int main()
{

	int age;
	cout << "Please enter your age:";
	cin >> age;
	if (age >= 21)
	{
		//all your code
	}
	else
	{
		cout << "You are to young" << endl;
	}
	return 0;
}


thank you! can't believe i didnt think of that
Topic archived. No new replies allowed.