While Problems

I am having trouble with a simple do while statement in which I want the code in the do statement to execute while a is true or while b is false. However the || operator does not seem to be working.

What is the reason for this? Any help would be great :)

Example:
while(p2win == (false) || p1win == (false))
a is true or while b is false.


Well, your code right there seems to be continuing while either one is false.

Also, I think your condition is incorrect anyway. You probably meant to keep going while neither player has won (both are false).
This should be fine, == has precedence over ||. There must be some other bug in your code.
Also, here you test if either is false, not if one is true and the other false.
Oops i meant both are false.
Anyways I did this test and I have the same problem.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>

using namespace std;

int main()
{
    bool test1(false);
    bool test2(false);

    do{cout << "hi";
    test2 = (true);
    }
    while(test1 == (false) || test2 == (false));
    return 0;
}
It should be outputting an infinite amount of "hi"'s. You test if test1 OR test2 are false, and while test2 will be true, test1 is still false.
So how can I make it so that if one of them is not false it will stop outputting?
I guess I would use && correct?
Use the and (&&) operator:
 
while(test1 == false && test2 == false);


EDIT: Correct. You figured it out yourself :D
Last edited on
Topic archived. No new replies allowed.