+ 1

Won't stop to take input on the 2nd question. How do I fix this? (Multiple choice questionaire)

#include<stdio.h> int main() { char choice; int s=0; printf("choose the correct letter of the answer.\n\nyour sister is a...\n\n"); printf("a. a boy\nb. a girl\nc. an alien\nd. a possesed demon\n"); printf("enter your answer:"); scanf("%c", &choice); if(choice=='b') { printf("correct\n"); s++; } else {printf("wrong the correct letter is b\n"); scanf("%c", &choice); } printf("your are a a...\n\n"); printf("a. a boy\nb. a girl\nc. an alien\nd. a possesed demon\n"); printf("enter your answer:"); scanf("%c", &choice); if(choice=='a') { printf("correct\n"); s++; } else {printf("wrong the correct letter is a\n"); s=s; } printf("final score is: %d \n\n", s); return 0; }

7th May 2020, 6:54 PM
janjan tantan
janjan tantan - avatar
1 Answer
+ 3
Add a space prior to %c in your scanf's to consume remaining whitespace and newline characters. scanf(" %c", &choice);
7th May 2020, 6:59 PM
ChaoticDawg
ChaoticDawg - avatar