Calculate average

Q: Write a program that ask the user how many people participated in a survey. It then inputs the height of each of the people and then calculates the average height.

This how I did it but it calculates the average height wrong.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
int main()
{
       float number;
       float height;
       float avarage;
       cout << "Enter the number of people that participated in a survey: " << endl;
       cin >> number;
       height = number;
              while (height != 0)
       {
       cout << "Enter the Height: " << endl;
       cin >> height;
       height += height;
       }
      
       avarage = height / number;
       cout << "Avarage is height is: " << avarage << endl;
return 0;
}
Line 13 doesn't make sense. Use avarage:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
       float number;
       int number = 0;
...
       float avarage = 0;
...
       height = number;
              while (height != 0)
              for(int i = 0; i < number; ++i)
...
       height += height;
       avarage += height;
...
      
       avarage = height / number;
       avarage /= number;
Topic archived. No new replies allowed.