0
#include<stdio.h>
int function()
{
  int test1;
  int test2;
  addit(test1 + test2);
  return(0);
}

void addit(test1 + test2)
{
  printf("Sum is: %d",test1 + test2);
}

Whenever I define a void function in C with an operator in the parameters, I always get the error:
error: expected ')' before '+' token

How do I fix this while still using the operator? Any help is appreciated.

3
Contributors
4
Replies
5
Views
8 Years
Discussion Span
Last Post by Dewey1040
0

Take your C textbook and look at the function definition paragraph.

void addit(int test1, int test2)
{
    ...
}

;)

0

See, the problem is, I can't do that. Your way creates mismatched type errors, and I am not allowed to change the call in the main function. The operator HAS to be in there.

0

See, the problem is, I can't do that. Your way creates mismatched type errors, and I am not allowed to change the call in the main function. The operator HAS to be in there.

Ahhh, of course, it's a function with a single parameter:

void addit(int x)

WHAT operator HAS to be in there? You have wrong C text now: senseless function header with an expression instead of parameter list + function call before the function definition or declaration ;)

0

call the function with this:

addit(test1 + test2);

then use this as the function definition:

void addit( int sumoftests ){

you are calling the function addit and sending it the sum of the two values. NOT sending it both variable test1 and test2... if you want to do that then add the variables inside the function like this:

#include<stdio.h>
int function()
{
  int test1;
  int test2;
  addit(test1, test2);
  return(0);
}

void addit( int test1, int test2 )
{
  printf("Sum is: %d", test1 + test2);
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.