so my program is suppose to stop when you enter 'X' or 'x'. i wrote
1 2 3 4 5 6 7 8 9 10 11
bool end;
end = true;
do{
cout << "please enter the candidates information (Enter 'x' to exit) " << endl;
****Code*****
}while (gender == 'x' || 'X');
end = false;
how ever this isnt working im not sure if im using the bool right. and when i tried to return a 0, it says an error "return value type does not match function type"
You need to compare gender against both 'x' and 'X'. That means having gender == appear twice in that line.
Now, another thing you could do is have only one comparison and feed gender into the tolower() function in the <cctype> header, however if you're not sure how to do this then don't stress out over it. :)
As for your second error... could we see the whole function?
-Albatross
*I wonder what the operators would look like. ?| or ?& look good to me.
this is my code so far. its running okay, but i think i could improve it a little more. i guess the problem was i had the while at the bottom so it was running everything else before checking the while. i don't like having the two if statements though, not sure how i can improve that though.
bool end = false;
do
{
//code.....
}while ( gender == 'x' ) || ( gender == 'X' ) );
end = true;
exit(1);
for some reason it runs the other code first instead of going straight to the while. but i ended up using an if statement. it runs fine i was just trying to find a different way.
1 2 3 4 5 6
if (gender == 'x' || gender == 'X')
{
end = false;
exit(1);
}
I tried a do-while so i wouldn't have an another if.
end = falsedo{
if ( gender == 'x' || gender == 'X' )
{
end = true;
break;
}
}while (!end);
cout << "succesful break"; // test to make sure it was getting out of the loop.
note:
just wondering when i declared end = true, at the beginning, then in the code if; end = false thewhile(!end) would end the program with out entering 'x'. and i want it to keep looping until you enter 'x'.
its about the (!end). im having trouble understanding what that does. i understand that it produces the opposite, i dont see how that gets out of the loop.
Well, you'd have your user input above the if statement, so the user would have entered something in to 'gender' and then if it's an x or X, then it will break; from the loop.
ahhh i see so it will do the code while end is false, but when the opposite ( end = true) is returned it goes onto the next set of code. okay thats so bad.
looking forward to starting computer science for this semester, that i'm trying to learn some stuff on my own before classes start.