C Program to Multiple Choice Question and Answer

How to write a C Program to Multiple Choice Question and Answer ( Choose an option from 1-4 please ) in C Programming Language ?



Solution:

  1.  #include <stdio.h>
  2.    
  3.     main ()
  4.     {
  5.         int num;
  6.         int count;
  7.         int ans;        // integer for ans
  8.        
  9.         printf("              MAIN MENU           \n");
  10.         printf("\n Choose an option from 1-4 please.  ");
  11.         scanf("%d", &num);
  12.        
  13.         switch (num)
  14.         case 1:
  15.         {
  16.             {
  17.            
  18.             printf("Enter the number of questions to be asked for this round of the quiz! (Max of 5 questions allowed). \n");
  19.             scanf("%d", &num);
  20.             flushall();
  21.             }
  22.        
  23.         case 2:
  24.         {
  25.             {
  26.                 printf("What is 1 x 5?");
  27.                 scanf("%d", &ans);
  28.                 flushall();
  29.        
  30.             }
  31.         if (ans==5)
  32.         {
  33.             ans = 1 * 5;
  34.             printf(" Correct! Next question!", ans);
  35.              = count++;
  36.         }
  37.         else
  38.         {
  39.             printf("Wrong! ans is 5!");
  40.         }
  41.        
  42.          printf("\n What is 10 /2?");
  43.             scanf("%d", &ans);
  44.             flushall();
  45.        
  46.            
  47.         if(ans==6)
  48.         {  
  49.             ans = 12/2;
  50.             printf(" Correct! Next question!", ans);
  51.         }
  52.         else
  53.         {
  54.             printf("Wrong! ans is 6!");
  55.         }
  56.        
  57.         break;
  58.         }
  59.    
  60.         case 3:
  61.            
  62.         {
  63.          
  64.            printf("You have ansed %d correct ans",   count);
  65.         break;
  66.         }
  67.        
  68.         default:
  69.             printf("End");
  70.         break;
  71.         }
  72.    
  73.         getchar();
  74.     }


Learn More :