Friday, July 31, 2009

C programming language error message. "source file not compiled"?

here is the program i try to run. can u tell me what is wrong with it. please try first for your self . if it runs successfully then tell me.


its about to calculate average of three numbers.


/*------------------------------------...


/* this program will compute and display the averageof three numbers. */


#include %26lt;stdio.h%26gt;


void main ( void )


double n1, n2, n3; /* the three input numbers */


{


double average; /* the average of three nubers */


printf( "/n compute the average of three numbers/n" );


printf( "-------------------------------------/n... );


printf( "please input three numbers:" );


scanf( "%1g%1g%1g" %26amp;n1, %26amp;n2, %26amp;n3 ); /* read the numbers */


printf( "averaging %g, %g, %g," n1, n2, n3, ); /* echo inputs */





average = (n1+n2+n3) / 3.0; /* average is sum / 3. */


printf( "the average is %g/n/n", average ); /* print average */


}

C programming language error message. "source file not compiled"?
void main( void )


double n1, n2, n3;


{





should instead be


void main( void )


{


double n1, n2, n3 ;





Putting the variables before the opening brace was the old way of declaring function parameters.





BTW, If you use a strict compiler, it would complain about you saying main returns void. It really should return int..





If your compiler has an option to check for and report more warnings, I highly recommend it. That will catch a lot of things for you.

thank you cards

No comments:

Post a Comment