I am hoping some one can help me out. I am trying to write a program that can read in 10 float numbers and print out their values to the screen. I also need to determine the largest, smallest, sum, average. I need to use an array. I have typed up alot of the code already, but I am having problems trying to compile what I have coded so far. Below is my code. Any input would be appreciated.

printf( "The sum of array n is %f\n", sum );
printf( "The avarage of array n is %f\n", average );
printf( "The array in ascending order is %f\n", n[10] );
printf( "The smallest number of array n is %f\n", smallest );
printf( "The largest number of array n is %f\n", largest );

Write and compile your program in small steps to ensure each part works.

08-29-2003

emmx

Thanks for your advice
I am still having trouble - I read the article that you provided the link for and I have been working on this for quite some time now (about 6 hours since I got the reply - but in that time I have done some research and more reading). I have altered my code but I still have a problem - I cannot figure out what is wrong with the line:

Code:

// arrange array in ascending order
for ( int i = 0; i < n; i++ )

I get the message for this line: ISO C++ forbids comparison between (this is in Dev C++)

printf( "The sum of array n is %f\n", sum );
printf( "The avarage of array n is %f\n", average );
printf( "The array in ascending order is %f\n", n[10] );
//printf( "The smallest number of array n is %f\n", smallest );
//printf( "The largest number of array n is %f\n", largest );

return 0; // indicates successful termination
} // end function main

Any input would be appreciated
Thankyou

08-31-2003

Dave_Sinkula

Quote:

Originally posted by emmx
I cannot figure out what is wrong with the line:

Code:

// arrange array in ascending order
for ( int i = 0; i < n; i++ )

Look at your own comment.

Quote:

Code:

int i; // counter
float n[10]; // n is an array of floats

Your complier rightly complains about trying to compare an int value with an array of floats.

There's plenty more going wrong here, though.

Code:

printf( "Enter 10 float numbers:\n" );
scanf( "%f", &n[10] );

This doesn't automagically read an array for you. Use a loop.

Code:

// average of contents of array n
for ( i = 0; i < 10; i++ )
{sum / 10;
} // end for

Ten times you calculate sum / 10 and throw the result away. But at least you got the loop condition right. (But you don't need a loop to calculate an average if you have a sum and the number of values.)