Apologies for the dumb question, I'm a bit of a beginner and am having trouble understanding why the following code will not work correctly.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int j = ' ';
int check = 0;
printf("\nPlease enter A, B, or C\n");
j = getch();
while(check == 0)
{
if(j != 'A' || 'B' || 'C')
{
printf("\nInvalid entry, please enter either an A, B, or C\n");
j = getch();
}
else
{
check = 1;
}
}
}
All I want this simple program to do is take in either A, B, or C using getch()
(Yes, I need to use getch()
) and use my while
loop to confirm the entry actually is either an A, a B, or a C. However, I run the program, and even when I enter an A, B, or a C, the program tells me my entry is not valid. Can someone help me here and tell me what I'm doing wrong?
I have a feeling this has to do with the fact that it reads in the character as an ASCII integer, but I'm really not sure how to fix this.