[Solved] Small program to calculate lowest, highest, and average of numbers in array (recalling C++)


Some mistakes of your code:

  1. If you want to take take 10 items then you have to iterate loop from 0 to 9 not 10 so for(int i = 0; i < 10; i++)
  2. You have to take array[i], not only i
  3. If you want to compare you have to write if (array[i] < array[i+1])
  4. Comparing isn’t correct. You are comparing between two items and storing high/low among them.

Total code after editing:

#include <iostream>

using namespace std;

int main( )
{
    int sum = 0;
    int avg = 0;
    int low = 999999;
    int high = 0;
    int array[11];

    cout << "Please enter 10 scores" << endl;
    cout << " - - - - - - - - - - - " << endl;

    for (int i = 0; i < 10; i++)
    {
        cout << "Please enter a score: ";
        cin >> array[i];
        //sum+=array[i];
    }

    for (int i = 0; i < 10; i++)
    {
        sum += array[i];

        if (array[i] < low)
        {
            low = array[i];
        }

        if (array[i] > high)
        {
            high = array[i];
        }
    }
    avg = sum/10;

    for (int i = 0; i < 10; i++)
    {
        cout << array[i] << endl;
    }

    cout << "The lowest score is: " << low << endl;
    cout << "...and the highest score is: " << high << endl;
    cout << "The average score is: " << avg << endl;

    return 0;
}

solved Small program to calculate lowest, highest, and average of numbers in array (recalling C++)