Average Heights

                Never    
C/C++
       
******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include<cctype> 

using namespace std;

int main()
{
    int height[10];    // Array of heights 
    int count = 0;    // Number of heights
    char reply = 0;  // reply to prompt
    // Input loop for heights. Read heights till we are done, or the array is full. 
    do
    {
        cout << endl; 
        cout << "Enter a height as an integral number of inches: ";
        cin >> height[count++];
        // Check if another input is required
        cout << "Do you want to enter another (y or n)? ";
        cin >> reply; 
    }while(count < 10 && tolower(reply) == 'y');
    // Indicate when array is full
    if(count == 10)
        cout << endl << "Maximum number of heights reached." << endl; 
        // Calculate the average and display it. 
        double average = 0.0; 
        for(int i = 0; i < count; i++)
        average += height[i]; // Add a height
        average /= count; // Divide by the number of heights
        cout << endl << "Average height is " << average << "inches. " << endl; 
        // Calculate how many are above average height 
        int above_average = 0; 
        for(int i = 0; i < count; i++)
        if(height[i] > average) // Greater than average 
        above_average++;        // then increment the count
        
        cout << "There "
             << (above_average == 1 ? "is " : "are ")
             << (above_average == 1 ? " " : "s ")
             << "above_average."
             << endl;
    return 0; 
    }

Raw Text