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;
}

Recommended Answers

All 3 Replies

You probably want an AND in that case
use the &&

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);

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.