error too few arguments to function: 'generateQuestions'

This is a discussion on error too few arguments to function: 'generateQuestions' within the C Programming forums, part of the General Programming Boards category; Hi sorry for asking to many questions but I have compiled the code for division and multiplication, which all ask ...

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    6

    error too few arguments to function: 'generateQuestions'

    Hi sorry for asking to many questions but I have compiled the code for division and multiplication, which all ask 10 random questions on both section and the user has to enter them. I'm receiving this error on line 37 and 66 ' too few arguments to function 'generateQuestions' . I would be tremendously grateful if anyone can help me on this.

    Thank you.

    Code:
    
    #include <stdio.h>
    #include <stdlib.h>
    
    int a;
    int b;
    int choice;
    
    #define SIZE 10
    
    //FUNCTION PROTOTYPE
    
    void generateQuestions(int a[], int b[], int c[], int d[]);
    void multiplication(int a[], int b[], int c[]);
    int printResult_multiplication(int a[], int b[], int ca[],int ua[]);
    void division(int a[], int b[], int d[]);
    int printResult_division(int a[], int b[], int ca[],int ua[]);
    
    //PROGRAM BODY
    
    int main(void)
    {
    
       printf("This program tests you with ten questions.\n 1) Multiplication\n 2) Division\n 3) Exit\n Please make a selection (1-3)\n");
       scanf("%d", &choice);
       if(choice==1)
       {
           int i;
        int ans;
        int x[SIZE];
        int y[SIZE];
        int answer[SIZE];
        int useranswer[SIZE];
        int score=0;
    
        srand(time(NULL));
    
        generateQuestions(x, y, answer);
        multiplication(x, y, useranswer);
        score= printResult_multiplication(x, y, answer,useranswer);
    
        if (score > 7)
        {
            printf("Congratulations! You scored %d/%d\n",score,SIZE);
    
        }
        else if (score <= 7)
    
        {
            printf("Please ask your teacher for help! You scored %d/%d\n",score,SIZE);
    
        }
       }
    else
    if (choice==2)
    {
        int i;
        int ans;
        int x[SIZE];
        int y[SIZE];
        int answer[SIZE];
        int useranswer[SIZE];
        int score=0;
    
        srand(time(NULL));
    
        generateQuestions(x, y, answer);
        division(x, y, useranswer);
        score= printResult_division(x, y, answer,useranswer);
    
        if (score > 7)
        {
            printf("Congratulations! You scored %d/%d\n",score,SIZE);
    
        }
        else if (score <= 7)
    
        {
            printf("Please ask your teacher for help! You scored %d/%d\n",score,SIZE);
    
        }
    }
    
        return 0;
    }
    
    //FUNCTION DEFINED
    
    
    //GENERATE QUESTION FUNCTION
    void generateQuestions(int a[], int b[], int c[], int d[])
    {
        int i;
        for(i=0; i<SIZE; i++)
        {
            a[i]=rand()%11;
            b[i]=rand()%11;
            c[i]=a[i]*b[i];
            d[i]=a[i]%b[i];
    
        }
    
    }
    
    //MULTIPLICATION FUNCTION
    void multiplication(int a[], int b[], int c[])
    {
        int i;
        int ans;
        printf("Please give the answers to the following additions:.\n");
    
        for(i=0; i<SIZE; i++)
        {
    
            printf("%d x %d = ",a[i],b[i]);
            scanf("%d",&ans);
            c[i]=ans;
        }
    }
    
    
    //DIVISION FUNCTION
    void division(int a[], int b[], int d[])
    {
        int i;
        int ans;
        printf("Please give the answers to the following additions:.\n");
    
        for(i=0; i<SIZE; i++)
        {
    
            printf("%d / %d = ",a[i],b[i]);
            scanf("%d",&ans);
            d[i]=ans;
        }
    }
    
    
    //PRINT DIVISION SUMMARY FUNCTION
    int printResult_division(int a[], int b[], int ca[],int ua[])
    {
        int i;
        int score=0;
        for(i=0; i<SIZE; i++)
        {
            printf(" %d / %d = %d  -", a[i],b[i],ua[i]);
            if(ua[i]==ca[i])
            {
                score=score+1;
                printf("Correct answer\n");
            }
            else
            {
                printf(" Incorrect answer - the answer is %d \n",ca[i]);
            }
        }
    
        return score;
    }
    
    
    //PRINT MULTIPLICATION FUNCTION
    int printResult_multiplication(int a[], int b[], int ca[],int ua[])
    {
        int i;
        int score=0;
        for(i=0; i<SIZE; i++)
        {
            printf(" %d * %d = %d  -", a[i],b[i],ua[i]);
            if(ua[i]==ca[i])
            {
                score=score+1;
                printf("Correct answer\n");
            }
            else
            {
                printf(" Incorrect answer - the answer is %d \n",ca[i]);
            }
        }
    
        return score;
    }

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    2,899
    You prototype your function as:
    Code:
    void generateQuestions(int a[], int b[], int c[], int d[]);
    Then you call your function like:
    Code:
    generateQuestions(x, y, answer);
    Your function prototype and your function and your function must all agree on the number and types of parameters, also the return type must be the same. Your prototype has 4 arguments and your function call only has 3.

    Jim

  3. #3
    Registered User
    Join Date
    Feb 2011
    Posts
    6
    Thank you so much, so I created another function for division which will generate questions for that. But I'm getting this error now 'undefined reference to 'generateQuestions_' and its not telling me at what line the error occurs. Do have any idea why that could be the case, here is my new code:

    Code:
    
    #include <stdio.h>
    #include <stdlib.h>
    
    int a;
    int b;
    int choice;
    
    #define SIZE 10
    
    //FUNCTION PROTOTYPE
    
    void generateQuestions_multiplication(int a[], int b[], int c[]);
    void generateQuestions_division(int a[], int b[], int d[]);
    void multiplication(int a[], int b[], int c[]);
    int printResult_multiplication(int a[], int b[], int ca[],int ua[]);
    void division(int a[], int b[], int d[]);
    int printResult_division(int a[], int b[], int ca[],int ua[]);
    
    //PROGRAM BODY
    
    int main(void)
    {
    
       printf("This program tests you with ten questions.\n 1) Multiplication\n 2) Division\n 3) Exit\n Please make a selection (1-3)\n");
       scanf("%d", &choice);
       if(choice==1)
       {
           int i;
        int ans;
        int x[SIZE];
        int y[SIZE];
        int answer[SIZE];
        int useranswer[SIZE];
        int score=0;
    
        srand(time(NULL));
    
        generateQuestions_multiplication(x, y, answer);
        multiplication(x, y, useranswer);
        score= printResult_multiplication(x, y, answer,useranswer);
    
        if (score > 7)
        {
            printf("Congratulations! You scored %d/%d\n",score,SIZE);
    
        }
        else if (score <= 7)
    
        {
            printf("Please ask your teacher for help! You scored %d/%d\n",score,SIZE);
    
        }
       }
    else
    if (choice==2)
    {
        int i;
        int ans;
        int x[SIZE];
        int y[SIZE];
        int answer[SIZE];
        int useranswer[SIZE];
        int score=0;
    
        srand(time(NULL));
    
        generateQuestions_(x, y, answer);
        division(x, y, useranswer);
        score= printResult_division(x, y, answer,useranswer);
    
        if (score > 7)
        {
            printf("Congratulations! You scored %d/%d\n",score,SIZE);
    
        }
        else if (score <= 7)
    
        {
            printf("Please ask your teacher for help! You scored %d/%d\n",score,SIZE);
    
        }
    }
    
        return 0;
    }
    
    //FUNCTION DEFINED
    
    
    //GENERATE QUESTION FUNCTION
    void generateQuestions_multiplication(int a[], int b[], int c[])
    {
        int i;
        for(i=0; i<SIZE; i++)
        {
            a[i]=rand()%11;
            b[i]=rand()%11;
            c[i]=a[i]*b[i];
    
    
        }
    
    }
    
    void generateQuestions_division(int a[], int b[], int d[])
    {
        int i;
        for(i=0; i<SIZE; i++)
        {
            a[i]=rand()%11;
            b[i]=rand()%11;
            d[i]=a[i]%b[i];
    
        }
    
    }
    
    
    //MULTIPLICATION FUNCTION
    void multiplication(int a[], int b[], int c[])
    {
        int i;
        int ans;
        printf("Please give the answers to the following additions:.\n");
    
        for(i=0; i<SIZE; i++)
        {
    
            printf("%d x %d = ",a[i],b[i]);
            scanf("%d",&ans);
            c[i]=ans;
        }
    }
    
    
    //DIVISION FUNCTION
    void division(int a[], int b[], int d[])
    {
        int i;
        int ans;
        printf("Please give the answers to the following additions:.\n");
    
        for(i=0; i<SIZE; i++)
        {
    
            printf("%d / %d = ",a[i],b[i]);
            scanf("%d",&ans);
            d[i]=ans;
        }
    }
    
    
    //PRINT DIVISION SUMMARY FUNCTION
    int printResult_division(int a[], int b[], int ca[],int ua[])
    {
        int i;
        int score=0;
        for(i=0; i<SIZE; i++)
        {
            printf(" %d / %d = %d  -", a[i],b[i],ua[i]);
            if(ua[i]==ca[i])
            {
                score=score+1;
                printf("Correct answer\n");
            }
            else
            {
                printf(" Incorrect answer - the answer is %d \n",ca[i]);
            }
        }
    
        return score;
    }
    
    
    //PRINT MULTIPLICATION FUNCTION
    int printResult_multiplication(int a[], int b[], int ca[],int ua[])
    {
        int i;
        int score=0;
        for(i=0; i<SIZE; i++)
        {
            printf(" %d * %d = %d  -", a[i],b[i],ua[i]);
            if(ua[i]==ca[i])
            {
                score=score+1;
                printf("Correct answer\n");
            }
            else
            {
                printf(" Incorrect answer - the answer is %d \n",ca[i]);
            }
        }
    
        return score;
    }


    Thanks

  4. #4
    Registered User
    Join Date
    Feb 2011
    Posts
    6
    never mind i figured it out, but I have just one last question, I'm asked to enter the quotient and not the remainder for the division case, how do I modify the division such that it prints out the quotient when there is a decimal case for example if 5/6 is 0.8333 than it should return 0 and if the user enters 0 it should return correct answer here is my code

    Code:
    
    #include <stdio.h>
    #include <stdlib.h>
    
    int a;
    int b;
    int choice;
    
    #define SIZE 10
    
    //FUNCTION PROTOTYPE
    
    void generateQuestions_multi(int a[], int b[], int c[]);
    void generateQuestions_divi(int a[], int b[], int d[]);
    void multiplication(int a[], int b[], int c[]);
    int printResult_multiplication(int a[], int b[], int ca[],int ua[]);
    void division(int a[], int b[], int d[]);
    int printResult_division(int a[], int b[], int ca[],int ua[]);
    
    //PROGRAM BODY
    
    int main(void)
    {
    
       printf("This program tests you with ten questions.\n 1) Multiplication\n 2) Division\n 3) Exit\n Please make a selection (1-3)\n");
       scanf("%d", &choice);
       if(choice==1)
       {
           int i;
        int ans;
        int x[SIZE];
        int y[SIZE];
        int answer[SIZE];
        int useranswer[SIZE];
        int score=0;
    
        srand(time(NULL));
    
        generateQuestions_multi(x, y, answer);
        multiplication(x, y, useranswer);
        score= printResult_multiplication(x, y, answer,useranswer);
    
        if (score > 7)
        {
            printf("Congratulations! You scored %d/%d\n",score,SIZE);
    
        }
        else if (score <= 7)
    
        {
            printf("Please ask your teacher for help! You scored %d/%d\n",score,SIZE);
    
        }
       }
    else
    if (choice==2)
    {
        int i;
        int ans;
        int x[SIZE];
        int y[SIZE];
        int answer[SIZE];
        int useranswer[SIZE];
        int score=0;
    
        srand(time(NULL));
    
        generateQuestions_divi(x, y, answer);
        division(x, y, useranswer);
        score= printResult_division(x, y, answer,useranswer);
    
        if (score > 7)
        {
            printf("Congratulations! You scored %d/%d\n",score,SIZE);
    
        }
        else if (score <= 7)
    
        {
            printf("Please ask your teacher for help! You scored %d/%d\n",score,SIZE);
    
        }
    }
    
        return 0;
    }
    
    //FUNCTION DEFINED
    
    
    //GENERATE QUESTION FUNCTION
    void generateQuestions_multi(int a[], int b[], int c[])
    {
        int i;
        for(i=0; i<SIZE; i++)
        {
            a[i]=rand()%11;
            b[i]=rand()%11;
            c[i]=a[i]*b[i];
    
    
        }
    
    }
    
    void generateQuestions_divi(int a[], int b[], int d[])
    {
        int i;
        for(i=0; i<SIZE; i++)
        {
            a[i]=rand()%11;
            b[i]=rand()%11;
            d[i]=a[i]%b[i];
    
        }
    
    }
    
    
    //MULTIPLICATION FUNCTION
    void multiplication(int a[], int b[], int c[])
    {
        int i;
        int ans;
        printf("Please give the answers to the following additions:.\n");
    
        for(i=0; i<SIZE; i++)
        {
    
            printf("%d x %d = ",a[i],b[i]);
            scanf("%d",&ans);
            c[i]=ans;
        }
    }
    
    
    //DIVISION FUNCTION
    void division(int a[], int b[], int d[])
    {
        int i;
        int ans;
        printf("Please give the answers to the following additions:.\n");
    
        for(i=0; i<SIZE; i++)
        {
    
            printf("%d / %d = ",a[i],b[i]);
            scanf("%d",&ans);
            d[i]=ans;
        }
    }
    
    
    //PRINT DIVISION SUMMARY FUNCTION
    int printResult_division(int a[], int b[], int ca[],int ua[])
    {
        int i;
        int score=0;
        for(i=0; i<SIZE; i++)
        {
            printf(" %d / %d = %d  -", a[i],b[i],ua[i]);
            if(ua[i]==ca[i])
            {
                score=score+1;
                printf("Correct answer\n");
            }
            else
            {
                printf(" Incorrect answer - the answer is %d \n",ca[i]);
            }
        }
    
        return score;
    }
    
    
    //PRINT MULTIPLICATION SUMMARY FUNCTION
    int printResult_multiplication(int a[], int b[], int ca[],int ua[])
    {
        int i;
        int score=0;
        for(i=0; i<SIZE; i++)
        {
            printf(" %d * %d = %d  -", a[i],b[i],ua[i]);
            if(ua[i]==ca[i])
            {
                score=score+1;
                printf("Correct answer\n");
            }
            else
            {
                printf(" Incorrect answer - the answer is %d \n",ca[i]);
            }
        }
    
        return score;
    }

  5. #5
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,640
    Code:
        generateQuestions_(x, y, answer);
    Multiplication or division? Eyeballing it, I'd say line 65 or 70.

  6. #6
    Registered User
    Join Date
    May 2010
    Posts
    2,899
    Code:
    generateQuestions_(x, y, answer);
    Where have you defined, implemented a function with this name?

    Also in future posts please include the entire error/warning message (cut/paste). These messages though sometimes cryptic usually provide information to aid diagnoses.

    Jim

  7. #7
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,640
    You're using the modulus (remainder) operation in your generateQuestions_divi function. You're doing
    Code:
    d[i] = a[i] % b[i]
    Which makes the quotient the remainder of the division, not the whole-number part. You should use the / operator if you want division. The more typical way would be to generate two random numbers, and store them in a[i] and b[i], then multiply them and store them in the quotient array. Ask your question as "What is quotient[i] / a[i]". That way you will always get something with a whole number answer.

    Also, you need to make sure the divisor (bottom number) isn't zero, otherwise you will get an divide-by-zero error.

  8. #8
    Registered User
    Join Date
    Feb 2011
    Posts
    6
    I have tried to enter d[i] = a[i]-(a[i]%b[i])/b[i] but for some reason the program crashes

  9. #9
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,640
    Probably the divide by zero that I mentioned. If b[i] is zero, the program will likely crash.

    I don't know what that formula you have is, but it's not going to give you a division problem.

    Start with a multiplication problem, like 7 * 8 = 56. Now, that can turn into two division problems, 56 / 7 = 8 and 56 / 8 = 7. Pick one of those two (doesn't really matter), then pick which two of the three numbers in that problem you want to give the user.

  10. #10
    Registered User
    Join Date
    May 2010
    Posts
    2,899
    Also remember that you are doing integer math, which means there are only whole numbers any fractional part of the calculation is truncated. And an value greater than zero and less than 1 will be truncated to zero.


    Jim

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 04:06 PM
  2. Arrays as function arguments :(
    By strokebow in forum C Programming
    Replies: 10
    Last Post: 11-18-2006, 03:26 PM
  3. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  4. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 07:18 AM
  5. qt help
    By Unregistered in forum Linux Programming
    Replies: 1
    Last Post: 04-20-2002, 10:51 AM

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