How to write a C Program to Multiple Choice Question and Answer ( Choose an option from 1-4 please ) in C Programming Language ?
Solution:
- #include <stdio.h>
- main ()
- {
- int num;
- int count;
- int ans; // integer for ans
- printf(" MAIN MENU \n");
- printf("\n Choose an option from 1-4 please. ");
- scanf("%d", &num);
- switch (num)
- case 1:
- {
- {
- printf("Enter the number of questions to be asked for this round of the quiz! (Max of 5 questions allowed). \n");
- scanf("%d", &num);
- flushall();
- }
- case 2:
- {
- {
- printf("What is 1 x 5?");
- scanf("%d", &ans);
- flushall();
- }
- if (ans==5)
- {
- ans = 1 * 5;
- printf(" Correct! Next question!", ans);
- = count++;
- }
- else
- {
- printf("Wrong! ans is 5!");
- }
- printf("\n What is 10 /2?");
- scanf("%d", &ans);
- flushall();
- if(ans==6)
- {
- ans = 12/2;
- printf(" Correct! Next question!", ans);
- }
- else
- {
- printf("Wrong! ans is 6!");
- }
- break;
- }
- case 3:
- {
- printf("You have ansed %d correct ans", count);
- break;
- }
- default:
- printf("End");
- break;
- }
- getchar();
- }