Can anybody help me figure out how to fix this so it would come out the highest & lowest score???

:

#include <iostream>
#include <iomanip>
using namespace std;

int main()

{
double *score;
double total = 0;
double average;
double max = 0;
double min = 0;
int testscore;
int count = 1;


cout << "Enter how many scores do you have: ";
cin >> testscore;
score = new double[testscore]; // Allocate memory



// Get the Test Scores
cout << "\n";

for (count = 1; count <= testscore; count++)
{
cout << "Enter score #"<<count<<": ";
cin >> score[count];
cout <<"\n";
}

// Calculate the total Scores
for (count = 1; count <= testscore; count++)
{
total += score[count];
}

// Calculate the average Test Scores
average = total / testscore;
if (score[count]> max)
{
max = score[count];
}
if (count == 0)
{
min = score[count];
}
if (score[count] < min)
{
min = score[count];
}

// Display the results
cout << fixed << setprecision(2);


cout <<"----------------------------\n";
cout <<"The highest score is: "<<max<<"\n\n";
cout <<"The lowest score is: "<<min<<"\n\n";
cout <<"The average score is: "<<average<<"\n\n";

system ("pause");
return 0;
}

line 28 and 36: array index values begin with 0, not 1. Those two loops will cause the program to write beyond the bounds of the array. Code them like this: for (count = 0; count < testscore; count++) You can do everything on just one loop -- no need to all those loops. After line 32 calculate the total and determine the highest and lowest values.

if( lowest > score[count])
   lowest = score[count];
if( highest < score[count])
   highest = score[count];

You need A "for" loop before checking the ancient dragon given condition.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.