Hi. I'm trying to find the Highest and Lowest value of testscores that I input them program. Along with the Students name next to the score when you figure out the highest and lowest scores.
#include <iostream>
usingnamespace std;
int main()
{
double scores[6];
int counter = -1;
do
{
counter++;
cout << "Please enter a score, then a name (enter -1 to stop both name and score entries): ";
cin >> scores[counter];
cout << "Please enter students name: ";
char student[20];
cin >> student;
}
while (scores[counter] >= 0);
double total = 0, average = 0, min = 101, max = 0;
for (int x = 0; x < counter; x++)
{
total += scores[x];
if (scores[x] > max)
max=scores[x];
if (scores[x] < min)
min=scores[x];
}
average = total/counter;
char student[20];
cout << "The average is " << average << endl;
cout << student << " has the highest score " << max << endl;
cout << student <<"has the lowest score " << min << endl;
system("pause");
return 0;
}
line 33 declares an uninitialized char[] and line 35 tries to use that uninitialized char[]...
line 15 goes out of scope when the while loop finishes...
it'd be better to use an array of strings to store each student's name char student[20]; only stores 1 name which gets overwritten each time that while loop goes through