Thread: my C pgm

my C pgm

From
Lisa Reilman
Date:
This program is suppose to have averagefunc that accepts 5 floating
point numbers as arguments and return the average to two decimal places.

I keep getting syntax errors on lines 6 & 26 and on line 29 is says
unspecified a,b,c,d,e.

I've tried everything.  What am I doing wrong?

1  /*Lisa Reilmann C pgm#1*/
2  /*This pgm averages 5 floating point numbers*/
3  #include <stdio.h>
4
5  float num1, num2, num3, num4, num4, num5, avg;
6  float averagefunc (float a, float b, float c, float d, float e);
7  main()
8  {
9  printf("Enter a floating point number");
10 scanf("%f", &num1);
11
12 printf("Enter another floating point number");
13 scanf("%f", &num2);
14
15 printf("Enter another floating point number");
16 scanf("%f", &num3);
17
18 printf("Enter another floating point number");
19 scanf("%f", &num4);
20
21 printf("Enter a final floating point number");
22 scanf("%f", &num5);
23 avg=averagefunc(num1, num2, num3, num4, num5);
24 printf("The average is %1.2f", avg);
25 }
26 float averagefunc (float a, float b, float c, float d, float e)
27 {
28 float avg1;
29 avg1=(a + b + c + d + e)/5;
30 return avg1;
31 }

Thanks
L. reilmann


Re: my C pgm

From
Date:
On Thu, 16 Nov 2000, Lisa Reilman wrote:

> This program is suppose to have averagefunc that accepts 5 floating
> point numbers as arguments and return the average to two decimal places.
>
> I keep getting syntax errors on lines 6 & 26 and on line 29 is says
> unspecified a,b,c,d,e.

Not sure what this has to do with PostgreSQL, but this compiled and ran
fairly cleanly for me, after I fixed one simple thing.

> 5  float num1, num2, num3, num4, num4, num5, avg;
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

No need to make these global variables outside of main.  You also declared
num4 twice.

It ran fine for me then.  What C compiler are you using?

Brett W. McCoy
                                     http://www.chapelperilous.net/~bmccoy/
---------------------------------------------------------------------------
CONGRATULATIONS!  Now should I make thinly veiled comments about
DIGNITY, self-esteem and finding TRUE FUN in your RIGHT VENTRICLE??