View Single Post
Old Apr 26th, 2005, 8:55 AM   #1
colt
Newbie
 
Join Date: Mar 2005
Posts: 7
Rep Power: 0 colt is on a distinguished road
Returning a value from a variable to the main function

Hi, I am having a big little problem to return to the main function, the value of a sum operation. As you can see in the code, all I want to do is to return the data contained in the 'res' variable (n1 + n2) to the main function.

There I call the function SUM through a call function "SUM (int res); "
to display in the end of the main function, the result of the sum: n1 + n2, but I get the following errors:

test.c: In function `main':
test.c:15: error: syntax error before "int"

So what I am doing wrong? What I need to do to sucessfully be able to return the data contained in the res variable to the main function to finally see the result of the mathematical operation?

Thanks in advance.

[code]#include <stdio.h>

int SUM (int n1, int n2);

main ()
{
int n1, n2, i;

while (5 == 5) {
printf ("To close the program, type 0: ");
scanf ("%d", &i);
if (i == 0) break;
printf ("Type the numbers that should be used to do the sum: ");
scanf ("%d %d", &n1, &n2);
SUM (int res);
}
}

int SUM (int n1, int n2)
{
int res;
res = n1 + n2;
printf ("The result is: %d", res);
return res;
}
colt is offline   Reply With Quote