#include <stdio.h>
int main(void) {
char UserInput;
int num = 10;
int counter = 0;
while (num != counter) {
printf("Enter the first letters ex A-Z:");
scanf("%c", & UserInput);
if (UserInput == 'A' || UserInput == 'a') {
printf("Uh-huh This is A. \n");
} else if (UserInput == 'B' || UserInput == 'b') {
printf("Uh-huh This is B. \n");
} else if (UserInput == 'Y' || UserInput == 'y') {
printf("Uh-huh this is Y. \n");
} else if (UserInput == 'g' || UserInput == 'G') {
printf("yeah G. \n");
} else {
printf(" unknown.\n");
}
counter++;
printf("Number of input remaining: %d\n", 10 - counter);
}
return 0;
}
The purpose of the program is to loop 10 times and report the information each time. for example, if the user enters "A" or "a" it should print "A". ... But during the execution of the second loop, it takes the print statement as user input.
Here is the output.
- Enter the first letters ex A-Z:a //entered a
- Uh-huh This is A. //output
- Number of input remaining: 9 //output
- Enter the first letters ex A-Z: unknown. //why is it taking Unknown as input?
- Number of input remaining: 8
- Enter the first letters ex A-Z: