• Register
1 vote


Hello, kodlogers,
I am writing codes in C/C++ nowadays. My code is about to add two numbers. I want to add those numbers by calling a function inside my may main function. But the program is not running for some reason. It’s saying Error: too many arguments in function call

What is this and why I am experiencing this error? Do you guys have any idea about it? Please, find my sample code below.

#include <stdio.h>
    int main()
      int num1, num2;
      int add_two_numbers ();
      num1 = 10;
      num2 = 25;
      add_two_numbers (num1, num2);
      add_two_numbers (1, 2);
add_two_numbers (int x, int y)               
      int z;
      z = x + y;
      printf ("%d\n", z);

Thanks guys for your kind help and pulling me out.

12 7 7
15,250 points

Please log in or register to answer this question.

1 Answer

1 vote
Best answer


I think you messed up between C and C++ compilers and you are compiling the c program in a C++ compiler. Compile the program as C instead of C++

Moreover, you need to correct/maintain the recent days' convention to write a program. As you are prototyping a method, you need to add the function name at the top of the main function with its data type. Keep in mind, it is better to initialize variables rather than assign. Remove the exit(0) from the code and put return 0 as I can see you didn’t add <stdlib.h> header in your program.

Let me put all the things in my way.

#include <stdio.h>
int add_two_numbers(int x, int y);
int main(void)
    int num1 = 10;
    int num2 = 25;
    add_two_numbers(num1, num2);
    add_two_numbers(1, 2);
    return 0;

int add_two_numbers(int x, int y)
    int z = x + y;
    printf("%d\n", z);

Now, the program should run fine and produce an output:



13 9 6
94,260 points

Related questions

1 vote
1 answer 68 views
Problem: Hello, I am pretty much novice in this programming world. I have started learning C programming a few days back. I am taking an online course. Today we learned a few things about functions and its prototyping. I am trying to solve a ... error: too few arguments to function multiply_two_numbers' multiply_two_numbers(); I am looking forward to having a legit solution. Thanks, mate.
asked Apr 26, 2020 Gavin 15.3k points
0 votes
1 answer 2 views
Problem: Hello! I am a beginner and I am trying to get some hands-on practice for functions in C++. I have written the following program in which I have declared a function that takes three parameters: #include<iostream> using namespace std; int func_1(int var1, ... . Please help me identify the error and resolve it. Please mention the changes that are to be made to resolve the error. Thanks!
asked 2 days ago Code Learner 9.5k points
0 votes
1 answer 19 views
I have this code: int max1 (int a, int b) {int m = a;  if (b> m) {m = b;  } return m;  } int main () {cout<< max1 (5,6) <<endl;  cout<< main () <<endl;  return 0;  } I have wanted to test that code but am afraid my computer will be damaged. What happens if the main () function is called?
asked Oct 1, 2020 sasha 16.2k points
1 vote
1 answer 203 views
Problem: Hello Experts, Well, I am looking for a simple solution. My problem might be silly to you guys but this thing driving me crazy so far. I&rsquo;ve bought an online course to learn C++ programming out of curiosity. Till this day I was doing good. I&rsquo; ... program that calls a function from another file. I mean, what is this? Could you please help out? I must recognize your help. Thanks.
asked May 3, 2020 Gavin 15.3k points
0 votes
1 answer 5 views
Problem: Hi there! I want to know that is there any way to declare a function that could take a variable number of arguments of the same type? I want something like follows: function(int arg1, arg2, &hellip;.) {} If there is such a mechanism, how can it be used? Please give an example. Thanks!
asked Mar 28 Code Learner 9.5k points
0 votes
1 answer 40 views
0 votes
2 answers 12 views
Problem: I have following code: #include<iostream> #include<conio.h> using namespace std; int cube ( int number) { return number * number * number; } Now, I want to call this function in my main() function. I tried the following: int main() { cube(); cout<<"The cube is "<<value; } But this is giving certain errors. I do not know what is wrong as I am a beginner. Please help. Thanks!
asked Mar 5 Code Learner 9.5k points
0 votes
1 answer 44 views
I want to know how to call to an overloaded function be ambiguous.
asked Oct 4, 2020 Daniel Anderson 4k points
0 votes
1 answer 29 views
What i am attempting to make a easy connection with XAMPP and MySQL server, however whenever I attempt to enter data or connect to the database, i obtain this error. Why this is happen and how to solve it?
asked Sep 14, 2020 Daniel Anderson 4k points
0 votes
1 answer 305 views
can someone help me why i am seeing &ldquo;PHP Fatal error: Uncaught Error: Call to undefined function mysql_query() in /Applications/MAMP/htdocs/lprapp/config.php:23 Stack trace:#0 {main} thrown in /Applications/MAMP/htdocs/lprapp/config.php on line 23&rdquo&rdquo; this error and how to resolve it.
asked Sep 14, 2020 Daniel Anderson 4k points