[Error] too few arguments to function

  • Thread starter Thread starter dect117
  • Start date Start date
  • Tags Tags
    Error Function
Click For Summary
SUMMARY

The forum discussion addresses a coding error encountered in a C program related to the function 'output_short_format'. The error message "[Error] too few arguments to function" arises from incorrect syntax when calling the function. The user mistakenly included data types in the function call instead of just passing the variable names. The solution involves removing the type declarations from the function call, as they are only needed in the function prototype and definition.

PREREQUISITES
  • Understanding of C programming syntax
  • Familiarity with function prototypes and definitions in C
  • Basic knowledge of data types in C
  • Experience with standard input/output functions in C
NEXT STEPS
  • Review C programming function syntax and best practices
  • Learn about function prototypes and their role in C programming
  • Explore debugging techniques for identifying function call errors in C
  • Study the use of mathematical functions from the math.h library in C
USEFUL FOR

C programmers, software developers, and students learning C who are troubleshooting function-related errors in their code.

dect117
Messages
25
Reaction score
1
So I'm writing some code for a project and I'm stuck on the first part. This code is obviously unfinished, but I tried testing it just to see how it was coming along and I kept getting the [Error] too few arguments to function 'output_short_format'. As far as I can tell, I'm passing three arguments into the function which takes three arguments. I don't see the problem.
C:
#include <stdio.h>
#include <math.h>
void output_short_format (double, double, double);
int main () {
    int x, amount, int_rate, term, mon_int_rate;
    printf ("Welcome to Mortgage Calculator!\nPlease select from the options below.\n\n");
    printf ("For 'Short Format' press 1\n\nFor 'Amortized Schedule' press 2\n\nFor 'Monthly Early Payments' press 3\n\nFor 'Yearly Early Payments' press 4\n\n");
    printf ("Where would you like to go? ");
    scanf ("%d", &x);
    if (x=1) {
        system ("cls");
        printf ("---------------------------------\n");
        printf ("           LOAN TERMS\n");
        printf ("---------------------------------\n");
        amount = 150000;
        int_rate = 4;
        term = 15;
        printf ("Loan Amount: %15d\n", amount);
        printf ("Interest Rate: %12d%%\n", int_rate);
        printf ("Term: %16d years\n", term);
        printf ("---------------------------------\n\n");
        mon_int_rate = int_rate/1200;
        output_short_format (double amount, double mon_int_rate, double term);
    }
}
    void output_short_format (double loan_amount, double interest_rate, double term_years) {
    int months, p;
    months = term_years*12;
    p = (loan_amount*interest_rate*pow (1+interest_rate, months))/(pow (1+interest_rate, months)-1);
    printf ("Monthly payment is: %12d", p);
    printf ("Total interest is: %12d", interest_rate); \\ignore
    printf ("Total amount paid is: %12d", term_years); \\ignore
}
 
Last edited by a moderator:
Physics news on Phys.org
Never mind, I figured it out.
 
Just in case, the problem is when you called your function -- don't declare the parameter types when you call a function. The declarations of the parameters go in the function prototype (which you have in the third line) and in the function definition.

Also, I changed your opening code tags slightly, using
C:
 instead of just [code].
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
11K
  • · Replies 5 ·
Replies
5
Views
4K
Replies
1
Views
4K
  • · Replies 11 ·
Replies
11
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
Replies
3
Views
3K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K