Jump to content

Archived

This topic is now archived and is closed to further replies.

qwe010

error in small code

Recommended Posts

hi all

i Found  this code   
i Tried to compiled it   
but he show error 
It needs to be some minor adjustments 

[code]#include <stdio.h>
#include <conio.h>
float average(float ary, float count)
{
float tot = 0.0;
        int i;

        for(i = 0; i < count; i++)
                tot += ary;

        return(tot / count);
}
int main()

{

printf("\n\t\t\t****************************
printf("\t\t\t****************************
printf("\t\t\t******** L-G-H Team ********
printf("\t\t\t****************************
printf("\t\t\t****************************
printf("\t\t            the result is %f\n", average(5.5, 3.5));
printf("\t\t\t        you got it :D\n\n");
printf(" press any key to exit...

getch();
return 0;
}[/code]

please

Share this post


Link to post
Share on other sites
The code is running perfectly fine provided you have closed all the printf statements.
Whats is the error you get?


Share this post


Link to post
Share on other sites
the error

error.c: In function `average':
error.c:8: error: syntax error before "i"
error.c: In function `main':
error.c:21: error: stray '\' in program
error.c:21: error: syntax error before "n"

Share this post


Link to post
Share on other sites
Hummm very strange which compiler are you using. I tried using Visual Studio 6.0 and no errors.

Share this post


Link to post
Share on other sites
i compiled under linux

I[quote] tried using Visual Studio 6.0 and no errors[/quote]

thin what the resault ?

Share this post


Link to post
Share on other sites
This is the output of the program


                        ****************************
                        ****************************
                        ******** L-G-H Team ********
                        ****************************
                        ****************************
                            the result is 6.285714
                                you got it :D

press any key to exit...



Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.