Help with do while loops
Nov 9, 2013 at 9:51am UTC
For some reason this loop is repeating no matter what the user inputs, also the while loop runs every time. I know the while loop isn't needed and their are easier ways to do it but i'm just learning and practicing some of the thing i'm learning
1 2 3 4 5 6 7 8 9 10 11 12
do {
cout << "\n[Y]es | [N]o\n" ;
cin >> done;
while ((done!='Y' ) || (done!='N' ) || (done!='n' ) || (done!='y' ))
{
error();
break ;
}
}while ((done!='Y' ) || (done!='N' ) || (done!='n' ) || (done!='y' ));
Nov 9, 2013 at 10:18am UTC
you could use an
if statement
instead of the inner
while loop
; i.e
1 2 3 4
if while ((done!='Y' ) || (done!='N' ) || (done!='n' ) || (done!='y' ))
{
error();
}
Good Luck, Zaki
Nov 9, 2013 at 11:57am UTC
Dreilly wrote:For some reason this loop is repeating no matter what the user inputs, also the while loop runs every time
The reason is this:
while ((done!='Y' ) || (done!='N' ) || (done!='n' ) || (done!='y' ))
This part must be:
while (done != 'Y' && done != 'N' && done != 'y' && done != 'n' )
Topic archived. No new replies allowed.