can someone point me in the right direction?

This is a discussion on can someone point me in the right direction? within the C Programming forums, part of the General Programming Boards category; I am trying to create a program to help people learn multiplication, and ask a question like, "What is 6 ...

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    4

    can someone point me in the right direction?

    I am trying to create a program to help people learn multiplication, and ask a question like, "What is 6 times 7?". I need a function to get random numbers, one to do the multiplitcation, and one to compare the answer from the user with the computer generated one. I'm having some trouble figuring it out... I've got some stuff down, basically just ideas. I'm pretty sure I'm way off, but could somebody just give me an idea of where to go with this?

    #include <stdio.h>
    #include <conio.h>
    #include <stdlib.h>
    #include <time.h>

    int random();
    int multiplication (int number1, number2);
    int compare (int number1, number1, answer);

    int main ()
    {
    int number1, number1;
    clrscr();
    srand(time(NULL))
    printf("How much is %d times %d?", rand ()%10, rand ()%10,);
    scanf("%d, %d", &number1, &number2);
    return number1, number2;
    }

    int multiplication (int number1, number2)
    {
    int answer;
    scanf ("%d", &answer);
    return answer;
    }

    int compare (int number1, number2, answer)
    {
    int correct;
    correct = number 1 * number2
    if correct == answer
    printf("Very good.");
    else
    printf("No, please try again.);
    }

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    You've got a few holes in your program, such as functionality that it needs. Here's a quick one from me, compare and contrast, then try and find other ways to do it.
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    
    static void checkAnswer ( int userAnswer, int compAnswer )
    {
      if ( userAnswer == compAnswer )
        printf ( "You answered correctly!\n" );
      else
        printf ( "Sorry, the answer was %d\n", compAnswer );
    }
    
    int main ( void )
    {
      int x, y, uAnswer;
      srand ( (unsigned)time ( NULL ) );
      do {
        x = rand() % 12, y = rand() % 12;
        printf ( "What is %d x %d? ", x, y );
        (void)scanf ( "%d", &uAnswer ); 
        while ( getchar() != (int)'\n' );
        checkAnswer ( uAnswer, ( x * y ) );
        printf ( "\nAnswer another? (y/n): " );
      } while ( toupper ( getchar() ) == (int)'Y' );
      return EXIT_SUCCESS;
    }
    -Prelude
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Mar 2002
    Posts
    4
    Thanks, I know I'm missing a lot....

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Point in the right direction
    By peanutym in forum C++ Programming
    Replies: 3
    Last Post: 07-07-2008, 09:49 PM
  2. Point me in the right direction
    By vampje in forum C++ Programming
    Replies: 0
    Last Post: 06-07-2006, 04:52 AM
  3. Array of pointers to point objects
    By totalfreeloader in forum C++ Programming
    Replies: 6
    Last Post: 11-27-2003, 09:26 AM
  4. trouble with overloaded operator
    By kkurz in forum C++ Programming
    Replies: 2
    Last Post: 10-31-2003, 12:59 PM
  5. fixed point / floating point
    By confuted in forum Game Programming
    Replies: 4
    Last Post: 08-13-2002, 02:25 PM

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