While Loop Does Not End

My while loop does not seem to end:

while (check=1)
{
cout<<"Please enter the number of people: "<<endl;
cin>>people;
if (people<6000&&people>0);
{
check=0
}
else
{
cout<<"Please enter a number between 0 and 6000"<<endl;
}
}

Even if the conditions are met, the check should be set to 0 and the loop should end but it does not seem to end?

Any help,
cheers
= is assignment
== is comparison
that does not seem to make a difference
It certainly does make a difference.

check = 1 is saying that check will always be assigned to 1, so the loop will never end since the condition is always met.

check == 1 is saying, if check equals 1

Can you post the whole code? It seems like you do not have any operation that changes the check variable
Your code would not compile anyway because of the semicolon after your if statement.
You can have an empty body for a conditional.
Some compilers generate a warning as this may indicate a logic error.
The actual error would come from the following else a few lines below it.
you had put the semicolon in front of 'if condition' . It is wrong . It is one type of function definition semi colon should not be there. And infront of 'check=0' semi colon should be there . Compiler is waiting for end of the statement.
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
while (check == 1)
{
     cout<<"Please enter the number of people: "<<endl;
     cin>>people;
     if (people<6000&&people>0)
     {
          check=0;
     }
    else
    {
          cout<<"Please enter a number between 0 and 6000"<<endl;
     }
}


(Insert if i had a dollar for everytime i meant to put = instead of == here)

Generally you should use the built in formats for code, because it's easier for people to show you what line of code has a problem, for this situation, you have an error on line 1 check = 1 is the incorrect syntax, as it will always evaluate to true, hense your error never ending, as well I don't understand how you compiled, because check = 0 did not have a semi colon on line 7, and on line 5 you have an out of place semicolon, maybe that was meant to be line 7. Your code should work just fine now though.
Thanks so much for your help!
Any time
Topic archived. No new replies allowed.