im having trouble using the bool operator in my program. for my program i have to use a bool function to determine whether three integers that represent three test scores are valid or not. the scores have to be from 0-100 including 0 and 100. if the score is invalid, the function will print a message explaining its invalid. if all three are valid, the function will return a signal to the main program saying this is a valid set of scores. and if any one of the three scores is invalid the function will return a signal saying this is an invalid set of scores. i tried many different things but none seem to work right. how am i supposed to do this. i tried something but i know its wrong but im not sure how to fix it. thanks for helping. this is what i put in the main:
1 2 3 4 5 6 7
bool ans;
ans= aretheyvalid(x, y, z);
if (ans==true)
cout<< "this group is valid" << endl;
else
cout<< "this group is invalid" << endl;
and this is the function:
1 2 3 4 5 6 7
bool aretheyvalid (int x, int y, int z) {
bool ans;
if (x >= 0 && y >= 0 && z >= 0 && x <= 100 && y <= 100 & z <= 100)
ans=true;
else
ans= false;
return ans;
sorry im confused. i added more to the bool function but it still doesnt work right. if doesnt do the anything after else. it keeps telling me they are all valid even when i type in a number that is bigger than 100.
bool aretheyvalid (int x, int y, int z) {
int invalid=0;
bool ans;
if (x >= 0 && y >= 0 && z >= 0 && x <= 100 && y <= 100 & z <= 100)
ans=true;
else {
ans= false;
if (x < 0)
cout<< x << "is too small" << endl;
if (y < 0)
cout<< y << " is too small" << endl;
if (z < 0)
cout<< z << "is to small" << endl;
if (x >100)
cout<< x << " is too big" << endl;
if (y > 100)
cout<< y << "is too big" << endl;
if (z > 100)
cout<< z << "is too big" << endl;
invalid++; }
return ans;
}
The function looks fine (other than the fact that you still have a bitwise and in there), so the problem must be in how you read the values or how you call the function.