# error too few arguments to function: 'generateQuestions'

• 02-19-2011
sunandstars
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; }```
• 02-19-2011
jimblumberg
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
• 02-19-2011
sunandstars
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
• 02-19-2011
sunandstars
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; }```
• 02-19-2011
anduril462
Code:

`    generateQuestions_(x, y, answer);`
Multiplication or division? Eyeballing it, I'd say line 65 or 70.
• 02-19-2011
jimblumberg
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
• 02-19-2011
anduril462
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.
• 02-19-2011
sunandstars
I have tried to enter d[i] = a[i]-(a[i]%b[i])/b[i] but for some reason the program crashes
• 02-19-2011
anduril462
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.
• 02-19-2011
jimblumberg
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