0

I am having trouble figuring out how to test 2 bools in a loop. This is an example.
do
{

}while (!done || !validMove);

#include <iostream>
#include <cmath>
using namespace std;

int main()
{

int number1,
number2,
total;

bool done = false,
validMove = false;

do
{

cout << "Enter a number" << endl;
cin >> number1;

cout << "Enter another number" << endl;
cin >> number2;

total = number1 + number2;
cout << total << endl;

if (number1 > 0)		//if number1 is more than 1, set done to true.
done = true;
else if (number2 >0)	//if number2 is more than 2, set validMove to true.
validMove = true;



}while (!done || !validMove);	//repeat while done is false or validMove is false.


return 0;
}
3
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by Johnnyj01
0

Or maybe its conceptually better to have one boolean :

bool done = false;
bool validMove = true;
bool shouldContinue = true;
do{
 //...
 shouldContinue = done && validMove; //should continue only if all test are passed
}while(shouldContinue);
0

Thank you very much for the help. I was able to fix the problem.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.