Jump to content


Photo

error in small code


  • Please log in to reply
8 replies to this topic

#1 qwe010

qwe010
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 26 September 2006 - 02:34 AM

hi all

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

#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;
}


please

#2 qwe010

qwe010
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 26 September 2006 - 02:41 AM

Youth 

I deleted this code   

\n");


Because the forum do  not accept

#3 qwe010

qwe010
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 26 September 2006 - 01:36 PM

up .......

#4 qwe010

qwe010
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 26 September 2006 - 11:49 PM

up .......

#5 shivabharat

shivabharat
  • Members
  • PipPipPip
  • Advanced Member
  • 371 posts
  • LocationChennai, India

Posted 01 October 2006 - 05:04 PM

The code is running perfectly fine provided you have closed all the printf statements.
Whats is the error you get?



Knowledge --- Reading Enriches Mind But Sharing Enhances It.[br][br]Note: Before you request help enusre that you have had a look at the tutorials @phpfreaks

#6 qwe010

qwe010
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 02 October 2006 - 09:18 AM

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"


#7 shivabharat

shivabharat
  • Members
  • PipPipPip
  • Advanced Member
  • 371 posts
  • LocationChennai, India

Posted 02 October 2006 - 04:19 PM

Hummm very strange which compiler are you using. I tried using Visual Studio 6.0 and no errors.
Knowledge --- Reading Enriches Mind But Sharing Enhances It.[br][br]Note: Before you request help enusre that you have had a look at the tutorials @phpfreaks

#8 qwe010

qwe010
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 03 October 2006 - 09:37 AM

i compiled under linux

I

tried using Visual Studio 6.0 and no errors


thin what the resault ?

#9 shivabharat

shivabharat
  • Members
  • PipPipPip
  • Advanced Member
  • 371 posts
  • LocationChennai, India

Posted 03 October 2006 - 04:24 PM

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




Knowledge --- Reading Enriches Mind But Sharing Enhances It.[br][br]Note: Before you request help enusre that you have had a look at the tutorials @phpfreaks




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users