As I have said lots of time son this forum, I really
hate dislike constructs like this:
1 2 3 4 5 6 7 8 9 10 11 12
|
do{// #3
cout<< "Enter q to quit or r to retry: ";
cin >> y;
}//do ends #1
while(y !='q' && y != 'Q' && y != 'r' && y!= 'R');
}
}//do ends #3
while(y == 'r' || y == 'R' );
|
First your do loops crossover - the end of #1 is in the middle of #3.
This is the bit I dislike: it's error prone, non-scalable & messy:
while(y !='q' && y != 'Q' && y != 'r' && y!= 'R');
If you really do need a do loop, then put the closing while on the same line as the closing brace, so readers don't confuse it for a null while loop:
} while(y == 'r' || y == 'R' ); //do ends #3
When trying to take care of lower & uppercase, make use of the
tolower
or
toupper
functions to halve the logic. But the logic is 2 sided : Quit or retry. So you could have a boolean variable called Retry say, if the input is 'N' then the program quits.
Also having an entire word as input which is then tested, is error prone:
if (d == "delete")
If the users enters that word with mixed case, it will fail. Best to stick with a single char as input.
I dislike do loops in this case as well - notice you have the tests twice? Much better with a while loop IMO.
This question is really a simple menu, search for some of the replies I (and others) have made. They use while loops with a switch inside.
I hope this has made it easier :+)