when I enter alphabet value or a symbol it will cause infinite loop. is there any solution i can solve this?
int main()
{
int input, input2, output;
printf("ENTER INPUT AS 1 OR 0 (1 AS TRUE AND 0 AS FALSE)");
printf("\nEnter your first input:");
scanf("%d", &input);
while (input != 0 && input != 1)
{
printf("Please enter a valid input:");
scanf("%d", &input);
}
printf("Enter your second input:");
scanf("%d", &input2);
while (input2 != 0 && input2 != 1)
{
printf("Please enter a valid input:");
scanf("%d", &input2);
}
output = input & input2;
printf("\n\nThe truth table of AND gate with given input is shown below\n\n");
printf("\t\tTruth Table");
printf("\n\nINPUT\t\tINPUT2\t\tOUTPUT");
printf("\n%d\t\t%d\t\t%d", input, input2, output);
_getch();
}