When I run the following snippet it runs until the second question. It then puts the “Is the customer a student? (y/n) \n” and “What is the movies time? (in hours) \n” prompts together (no area to answer between them). If one takes any action from there on, the program stops working. What did I do wrong? (i’m pretty sure it’s syntax related)
int A,B,C,D,age,time;
char edu, ddd;
printf ("What is the customer's age? \n");
scanf("%d", &age);
printf ("Is the customer a student? (y/n) \n");
scanf("%c", &edu);
printf ("What is the movies time? (in hours) \n");
scanf("%d", &time);
printf ("Is the movie 3-D? (y/n) \n");
scanf("%c", &ddd);
You probably need to eat the extra input from stdin after each scanf so it doesn’t stick around in the buffer and cause scanf to receive the buffered data.
This is because the newline from hitting enter after the first text entry stays in the buffer and is a valid entry for the “%c” format – if you look at the value of “edu” you should find it’s a newline character.