Search code examples
cwhile-loopgetchar

Breaking a while loop with more than one character in c programming


How do i get this snippet of code to break the while loop with both "a" and "A"? I can't get the OR function right. Thanks in advance for the help.

while((product = getchar()) !='a')


Solution

  • If you want to break the loop when product is a or A, you need to check if product is not a and not A in your loop condition:

    while((product = getchar()) !='a' && product != 'A')