I have the following simple C code where the user is expected to ask several questions in this particular order, among them are "What is your name?" and "What is your favourite color?". To make sure the answer the program gives matches the appropriate question, I do strcmp. However, when I input the correct question, it outputs two lines of ??? and terminates the program, skipping the second input rather than answering with "Bob" When I enter the incorrect input for the first question, it doesn't skip the second input.
What is wrong here and how can I fix it?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void) {
char questionOne[50];
char questionTwo[50];
scanf("%s", questionOne);
if(strcmp(questionOne, "What is your name?\n") == 0) {
printf("Bob\n");
}
else {
printf("???\n");
}
scanf("%s", questionTwo);
if(strcmp(questionTwo, "What is your favourite colour?\n") == 0) {
printf("Blue\n");
}
else {
printf("???\n");
}
return 0;
}