Question bout my work

This is a discussion on Question bout my work within the C Programming forums, part of the General Programming Boards category; Code: printf ("1.Enter the number of questions to be asked for this round of the quiz\n\n"); //Number of quizs printf ...

  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    1

    Question bout my work

    Code:
        printf ("1.Enter the number of questions to be asked for this round of the quiz\n\n");      //Number of quizs
        printf ("2.Start quiz\n\n");                                                                //Run questions
        printf ("3.Display the number of questions answered (i) correct and (ii) incorrect\n\n");   //Display results
        printf ("4.Exit Program\n\n");                                                              //Exit Program
        printf ("Enter option : \n\n");
        scanf  ("%d", &Selection);
        
     if (Selection == 1)
                 {
                      printf ("How many  Question would you like to be asked? [ 1 - 4 ]\n");
                      scanf  ("%d\n", &SelectionQuestions);
                 }
     else if (Selection == 2)
                 {
                        printf ("                           --------------------------\n");
                        printf ("                            -[-[ Question Begin ]-]- \n");
                        printf ("                           --------------------------\n\n");
                        printf ("----------------\n");
                        printf ("- 1st Question -\n");
                        printf ("----------------\n");
                        printf ("What is 1 + 1 = ?\n");
                        scanf  ("%d", &answer);
     if (answer ==2)
                        printf("\nYou got it right!!!\n\n\n");
     else
                        printf("\nThe answer is incorrect , the correct answer is 2\n\n\n");
                        
                        printf ("----------------\n");
                        printf ("- 2nd Question -\n");
                        printf ("----------------\n");                   
                        printf("What is 10 - 5 = ?\n");
                        scanf("%d",&answer);
     if (answer ==5)
                        printf("\nYou got it right!!!\n\n\n");
     else
                        printf("\nThe answer is incorrect , the correct answer is 5\n\n\n");
                        
                        printf ("----------------\n");
                        printf ("- 3rd Question -\n");
                        printf ("----------------\n");   
                        printf("What is 3+4-10= ?\n");
                        scanf("%d",&answer);
     if ( answer ==-3)
                        printf("\nYou got it right!!!\n\n\n");
     else
                        printf("\nIncorrect! The correct answer is -3\n\n\n");
                        
                        printf ("----------------\n");
                        printf ("- 4th Question -\n");
                        printf ("----------------\n");   
                        printf("What is 10+20+4-10 = ?\n");
                        scanf("%d",&answer);
     if ( answer ==24)
                        printf("\nYou got it right!!!\n\n\n");
     else
                        printf("\nIncorrect! The correct answer is 24\n\n\n");
    
                 }
                 
       system("PAUSE");	
      return 0;
    }
    tis part of my assignment.
    i cant figure the part where i select how many question to be asked that part.
    can any1 just tutor me or show me any tutorial which is similar to it?

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    74
    A few ideas:
    - try to move the questions from the main to a function, and in main you could use a loop for the menu, and instead of if else, a switch might look nicer.

    - you probably should ask first for the number of questions before showing the the menu, otherwise someone might start the quiz without specifying the number of questions.

    - send the SelectionQuestions as a parameter to the function and then, depending on the value, call the appropriate number of questions.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Add some random numbers for the arithmetic to be done on.

  4. #4
    Registered User
    Join Date
    Jul 2010
    Posts
    33
    You should also be checking the return value of scanf. It will return the number of items read, you should make sure it is reading in the same amount as variables you have after the format string.

  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,447
    What you need to do first of all is fix your indentation. It's impossible to see what belongs where.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 11-14-2005, 05:23 AM
  2. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  3. The Bludstayne Open Works License
    By frenchfry164 in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 11-26-2003, 10:05 AM
  4. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 11:39 AM
  5. Question type program for beginners
    By Kirdra in forum C++ Programming
    Replies: 7
    Last Post: 09-15-2002, 05:10 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21