# Thread: expected expression before 'double' (sum problem with functions)

1. ## expected expression before 'double' (sum problem with functions)

I'm a beginner with programming in C and I have a problem to solve at which I get stucked.
So my program reads positive numbers until the value 0 then it calculates the sum of numbers. Then I have to write a function which displays the sum. Also, after that I need to enterr a number "y" from keyboard and I need to find the result of the sum/y.
My program needs to be built with functions. I received the functions name with parameters and I built them like this:
Code:

Code:
```#include <stdio.h>

// Shows a message with what the program is doing.
void ShowIntroduction(void)
{
printf("My program finds a sum etc");
}

// find the sum of the numbers enter until 0 value
int sum(void)
{
int s=0,n;
do
{
scanf("%d",&n);
if (n > 0)
s=s+n;
}
while(n != 0);

return s;
}

// show the result
void sumResult(int a)
{
printf("The sum is %d", a);
}

// find the result of sum/y
double result(int s,int y)
{
double res;
res=double(s)/double(y);
return res;
}

int main()
{
int y;
scanf("%d",&y);
ShowIntroduction();
sumResult(sum());
result(sum(),y);

return 0;
}```

The problem is that I get the error: "expected expression before 'double' "
Where is my mistake? 2. Code:
`res=double(s)/double(y);`
The above is not valid C code.
Lookup how to do C casting.

Tim S. 3. Thanks!
I solved the problem.Now, I got another one.
The program shows the sum result then it asks me to introduce the values again until the value 0 then the program closes.
Like in the picture below: The program should display the result of 10/2 in this case but I don't know why is not working. 4. That's clear,
because yo call the function 'sum' first in line 47 as the first argument of function 'sumResult'
and then in line 48 again. The variable 'n' is only valid in 'sum', after calling 'sum' again, the
last value is away. By the way you should insert a line to show the quotient of '(doublel)sum/(double)y'
and one who shows what is to put in by variable 'y'
May be it is also better to set first the quantity, how much values you want to read in.
If you want for example to calculate the average temperatures in Celsius or in Farenheit it would be
possible that you can get an Value of Zero degree. But in the example above you can't calculate
the average, you can't save a value of Zero.

Code:
```#include <stdio.h>

// Shows a message with what the program is doing.
void ShowIntroduction(void)
{
printf("My program finds a sum etc\n");
}

// find the sum of the numbers enter until 0 value
int getsum(int *s)
{
int n;

*s = 0;
do
{
printf("Enter a integer: ");
scanf("%d", &n);
if (n > 0)
*s += n;
}
while(n != 0);

return *s;
}

// show the result
void sumResult(int a)
{
printf("The sum is %d\n", a);
}

// find the result of sum/y
double result(int s,int y)
{
double res;
res=double(s)/double(y);
return res;
}

int main()
{
int y, sum;

ShowIntroduction();

printf("Enter divisor: ");
scanf("%d",&y);

sumResult(getsum(&sum));
printf("quotient: %lf\n", result(sum,y));

return 0;
}``` 5. What a crappy way to structure a program (just my opinion) Popular pages Recent additions double, int, program, return, sum 