if/else problems within loop

Hi everybody! i have written an exercise i found here on cplusplus.com. I compile it and everything goes well, but the if statement at line 20, doesnt work. Any suggestions?

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
// While( user == gullible ) exercise
#include <iostream>
using namespace std;

int guess_count;
int n;

int main()
{
    cout<<"Enter any number other than 5."<<endl;
    while (1) {
          guess_count=0;
          cout<<"Enter number: "<<endl;
          ++guess_count;
          cin>>n;
          if (n==5) {
                   cout<<"Hey! you weren't supposed to enter 5!"<<endl;
                   break;
                   }
    if (guess_count >= 10) {
                    cout<<"Wow, you're more patient then I am, you win."<<endl;
                    break;
                    }
          else cout<<"Enter number again"<<endl;
           }
    system ("PAUSE");
    return (0);
}
    
closed account (z05DSL3A)
Set guess_count=0; outside of the while loop.
thank you grey wolf, i made it as you said, and it worked! cheers! :D
You should declare guess_count and n withing your main function, you should try to avoid using global variables unless its absolutely necessary.
@aggsyb thnx for the tip! i shall keep that in mind.
Topic archived. No new replies allowed.