It wont update or react to an updated int x

I was doing the challenges on this website and came upon a problem

The code is supposed to ask you for a number other than 5
When you give it a number other than 5 it will ask again 10 times and if you haven't put 5 in those 10 tries it will give up but if you did input 5 it tells you you weren't supposed to do so and quits

Its sort of an annoying program

But my problem is that it doesn't quit after the 10nth try
Its supposed to update the variable and when it does the if statement takes over and the program gives up
But it doesn't and i cant really see anything wrong with it

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
#include <iostream>

using namespace std;

int main()
{
    int num,x;
    x=0;

    cout<<"Enter any number but 5! "<<endl;
    cin>>num;

    while (num != 5){
        cout<<"Enter any number but 5! "<<endl;
        cin>>num;
        x++;
    }

if (x == 10){
    cout<<"Wow, you're more patient than I am, you win."<<endl;
    return 1;
}

if (num == 5){
    cout<<"Hey! you weren't supposed to enter 5!"<<endl;
}


}


It looks fine to me
But it doesn't work right
Last edited on
You accidentally put the if statement outside of the loop. The only way for the program to get to line 18 is to enter 5 (and thus, line 24 is redundant).
Last edited on
Thanks LB!

You really cleared that up for me, i didn't realize that.

Thanks!
Topic archived. No new replies allowed.