HELP this array is kicking my butt

it compiles and runs, it gives me the average and the highest score but says lowest is 0 even though 0 is never entered.

//Write a program which uses an array of 5 scores and calculates the average score, the highest score and the
//lowest score.
#include <iostream>
using namespace std;

int getHighest(int [], int);
int getSmallest(int [], int);
double getAverage(int [], int);
int count;
int numbers;

int main()
{
const int SIZE = 5;
int scores[SIZE];
double average;
int biggest, smallest;

for(int i=0; i<SIZE; i++)
{
cout << "Enter score for student: " << i+1 << ": " ;
cin >> scores[i];
while(scores[i] > 100 || scores[i] < 0)
{
cout << "Invalid score. Enter value between 0 and 100" << endl;
cin >> scores[i];
}

}

average = getAverage(scores, SIZE);
cout << average << endl;
biggest = getHighest(scores, SIZE);
cout << biggest << endl;
smallest = getSmallest(scores, SIZE);
cout << smallest << endl;

system("pause");
return 0;
}


//get maximum value

int getHighest( int total[], int s)

{

int biggest;

for(int i = 0; i < s; i++)
{
if (total[i] >biggest)
biggest = total[i];
}
return biggest;
}

//get min value

int getSmallest (int total[], int s)

{
int smallest;

for(int i = 99; i < s; i++)
{
if (total[i] < smallest)
smallest = total[i];
}
return smallest;
}


double getAverage(int ar[], int size)
{
double total= 0, avg;
for(int i=0; i<size; i++)
total += ar[i];

avg = total/size;
return avg;

}
In getHighest and getSmallest, biggest and smallest are random values. You don't initialize them to anything, it is only by chance that one works at all.

1
2
3
4
5
6
7
8
9
10
11
int getHighest( int total[], int s)
{

    int biggest = total[0] ;

    for(int i = 1; i < s; i++)
        if (total[i] >biggest)
            biggest = total[i];

    return biggest;
}


thankyou a second set of eyes is always a help
Topic archived. No new replies allowed.