#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.

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

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

;)

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.

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 ;)

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 article has been dead for over six months. Start a new discussion instead.