# Thread: Finding Average of floats

1. ## 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;

}```

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

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

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

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

6. ## Another Question

Now how would i make the program to display which numbers have exceeded the average?

7. You can use a conditional statement (like an if...)

8. that would be pretty simple..

for each score
if score > average
print score is higher than average

9. I can't resist...

Code:
```cout << "Numbers that exceed average: ";

for(int j = 0; j < 10; j ++)
{
if(a[j] > average)
{
cout << a[j] << " ";
}
}```

Popular pages Recent additions