# Finding Average of floats

• 12-01-2002
sonict
Finding Average of floats
can some one tell me whats wrong with this program. i'm trying to find average of 10 floats and how do i use code tags?
Code:

```#include <iostream.h> #include <iomanip.h> void main() {         // declare all variables         float a[10];                 // ask user for numbers         cout << "What are the floating point numbers?" << endl;         cin  >> a[10];                 float average;         average = ((a[1]+a[2]+a[3]+a[4]+a[5]+a[6]+a[7]+a[8]+a[9]+a[10])/10);         cout << "The average is " << average << endl;         }```
• 12-01-2002
kermi3
I added the code tags for you, but here's how you use them:

put [code] before your code, then [/code] after your code and voila...check the link in my signture for more...

(looks like this when typing)

[code]

cout << "hi";

[/code]
• 12-01-2002
well, first you need to actually get the floats from the user

Code:

```for(int i = 0; i < 10; ++i) {   cout<<"Enter number: ";   cin>>a[i]; }```
code tags are

[ code ]
and
[ /code ]

without the spaces.
• 12-01-2002
sonict
thank you very much for adding code tags. i haven't used the board since a while and forgot. And thanks for that program help.
Thank you.
• 12-01-2002
abrege
Code:

```#include <iostream.h> int main() {         float a[10];         cout << "What are the floating point numbers?" << endl;         for(int i = 0; i < 10; i ++)         {                 cin >> a[i];         }         float average;         average = ((a[0]+a[1]+a[2]+a[3]+a[4]+a[5]+a[6]+a[7]+a[8]+a[9])/10);         cout << "The average is " << average << endl;         return 0; }```
Remember the base of an array is 0
• 12-01-2002
sonict
Another Question
Now how would i make the program to display which numbers have exceeded the average?
• 12-01-2002
Mister C
You can use a conditional statement (like an if...)
• 12-01-2002
```cout << "Numbers that exceed average: "; for(int j = 0; j < 10; j ++) {         if(a[j] > average)         {                 cout << a[j] << " ";         } }```