I have to write a program that calculates the avg, min, and max. The program runs fine, but when a user decides he doesn't want to enter any scores (enter: -1) in the beginning it still tries to calculate the avg,min and max.
I need the program to end w/o trying to calculate the mean, etc if the user enters -1 for the first value.
Thanks in advance.
int main()
{
double score[75];
int x = -1;
double total = 0;
double min = 101;
double max = -1;
do
{
x++;
cout << "Please enter a score (enter -1 to stop): ";
cin >> score[x];
if (score[x] < min)
{
if (score[x] != -1)
min = score[x];
}
if (score[x] > max)
{
max = score[x];
}
}
while (score[x] != -1);
for (int y = 0; y < x; y++)
{
total += score[y];
}
cout << "Average is " << (total / (double)(x)) << endl;
cout << "Highest is " << max << endl;
cout << "Lowest is " << min << endl;
}