Thread: Math Quiz Program Help

  1. #1
    Registered User
    Join Date
    Nov 2014
    Posts
    3

    Math Quiz Program Help

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    
    
    void correctResponse(void);
    void incorrectResponse (void);
    void multiplication( void ); // function prototype
    
    
    int main( void )
    {
    int correct, incorrect;
    
    
       srand( time( NULL ) ); // seed random number generator
       multiplication(); // begin multiplication practice
    } // end main
    
    
    void correctResponse(void)
    {
        int correct;
     correct= correct + 1;
        switch(rand()%4)
        {
        case 0:
            puts("Very good!");
            break;
    
    
        case 1:
            puts("Excellent!");
            break;
    
    
        case 2:
            puts("Good Job!");
            break;
    
    
        case 3:
            puts("You're Amazing!");
            break;
        }
    }
    void incorrectResponse(void)
    {
        int incorrect;
        incorrect= incorrect + 1;
        switch(rand()%4)
        {
        case 0:
            puts("Nice Try");
            break;
    
    
        case 1:
            puts("You Suck!");
            break;
    
    
        case 2:
            puts("Maybe Next Time!");
            break;
    
    
        case 3:
            puts("Terrible!");
            break;
        }
    }
    // multiplication produces pairs of random numbers and
    // prompts user for product
    void multiplication( void )
    {
        int correct, incorrect;
       int x; // first factor
       int y; // second factor
       int response = 0; // user response for product
        int total;
       // use sentinel-controlled repetition
       puts( "Enter -1 to end." );
    
    
       // loop while sentinel value not read from user
       while ( response != -1 ) {
          x = rand() % 10; // generate 1-digit random number
          y = rand() % 10; // generate another 1-digit random number
    
    
          printf( "How much is %d times %d? ", x, y );
          scanf( "%d", &response );
    
    
          // loop while not sentinel value or correct response
          while ( response != -1 && response != x * y ) {
             incorrectResponse();
             scanf( "%d", &response );
          } // end while
    
    
          // correct response
          if ( response != -1 ) {
            correctResponse();
          } // end if
       } // end while
     total= (correct/(incorrect+correct));
     if (total >= .75) {
        printf("Congratulations, You are ready for the next level!");
     }
        else {
            printf("Please ask your Teacher for extra help.");
        }
    
    
    
    
       puts( "That's all for now. Bye." );
    } // end function multiplication


    // It keeps crashing. How do I compile the responses into a grade? Thank you!

  2. #2
    Registered User
    Join Date
    Nov 2014
    Posts
    3
    To clarify, this is not a quiz I am taking. It is an exercise from my textbook.

  3. #3
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,114
    Turn on or turn up the Warning level on your compiler, and correct the warnings & errors first. Then test, then ask if you still have any questions.

  4. #4
    Registered User
    Join Date
    Nov 2014
    Posts
    3
    I'm using codeblocks. It isn't prompting any errors.

  5. #5
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,114
    Quote Originally Posted by HystericalFool View Post
    I'm using codeblocks. It isn't prompting any errors.
    See: https://latedev.wordpress.com/2012/1...deblocks-tips/ Tip #3

    I don't use Code::Blocks myself.

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,662
    Here,
    Code:
    $ gcc -Wall bar.c
    bar.c: In function ‘main’:
    bar.c:13:14: warning: unused variable ‘incorrect’ [-Wunused-variable]
    bar.c:13:5: warning: unused variable ‘correct’ [-Wunused-variable]
    bar.c:18:1: warning: control reaches end of non-void function [-Wreturn-type]
    bar.c: In function ‘correctResponse’:
    bar.c:24:9: warning: ‘correct’ is used uninitialized in this function [-Wuninitialized]
    bar.c: In function ‘incorrectResponse’:
    bar.c:50:14: warning: ‘incorrect’ is used uninitialized in this function [-Wuninitialized]
    bar.c: In function ‘multiplication’:
    bar.c:108:28: warning: ‘incorrect’ is used uninitialized in this function [-Wuninitialized]
    bar.c:108:28: warning: ‘correct’ is used uninitialized in this function [-Wuninitialized]
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A simple Advice will do..(Quiz Program)
    By Jimboynoob in forum C Programming
    Replies: 7
    Last Post: 08-28-2012, 08:44 AM
  2. Stucked! Identification Quiz Program..
    By Jimboynoob in forum C Programming
    Replies: 2
    Last Post: 08-20-2012, 10:06 AM
  3. Simple quiz program problem
    By paulb39 in forum C++ Programming
    Replies: 22
    Last Post: 03-05-2010, 05:13 PM
  4. Hi, Quiz C program
    By Eman in forum C Programming
    Replies: 0
    Last Post: 11-11-2009, 04:12 PM
  5. making a math quiz program
    By mackieinva in forum C Programming
    Replies: 10
    Last Post: 09-17-2007, 03:38 PM