Can't exit a do/while loop - please help
I was wondering if anyone might be able to tell me why the program won't exit the loop when response equals 'q' or 'Q'. When I select a Q or a q, the program just loops contiuously. Any help would be appreciated.
printf("Please select a transaction:\n");
printf("Cheque - C or c\nDeposit - D or d\nPrint - P or p\nQuit - Q or q\n");
case 'd': case'D':
case 'p': case'P':
case 'q': case'Q':
printf("That is an invalid selection. Please try again.\n ");
Look at the logic in your while condition
if you look at the logic of the statment
(response!='q') is true(1) when any other letter is entered and false(0) when you enter 'q'
(response!='Q') is true(1) when any other letter is entered and false(0) when you enter 'Q'
one is always going to be true and the other false when you try to quit
when you OR 1 and 0 you get 1 which is what you are doing so it evaluates to while(1) which is an infinite l oop
when you AND 1 and 0 you get 0 which will break the loop and exit so just change the || to && and you should be alright.