SO im writing a program that will ask the user for how many scores they would like to enter then using list arrays i need to input those sort them output the max and min and so on the only thing that i cannot figure out is that i need to prompt the user on how many scores to enter but have a const int MAX_SCORES = 6 but even if they enter something higher then 6 i should still enter values but not store them when i output?
#include <iostream>
usingnamespace std;
#include <cstdlib>
struct test
{
int score;
};
int compare(constvoid* pa, constvoid* pb)
{
constint& a = *static_cast<constint*>(pa);
constint& b = *static_cast<constint*>(pb);
if (a < b) return -1;
if (a > b) return 1;
return 0;
}
double getAverage(int* score, int n)
{
double average = 0;
int i = 0;
for (i = 0; i < n; i++)
average += average / n;
return average;
}
int main()
{
int n;
cout << "How many scores would you like to record?: ";
cin >> n;
cin.ignore(1000, 10);
cout << endl;
constint MAX_SCORES = 6;
int nScores = 0;
int score[MAX_SCORES];
// read and save the scores
while (nScores < n)
{
int aScore;
cout << "Enter score: ";
cin >> aScore;
cin.ignore(1000, 10);
if (nScores < MAX_SCORES)
score[nScores++] = aScore;
}
int i;
int max = score[0];
for (i = 1; i < nScores; i++)
if (max < score[i]) max = score[i];
int min = score[0];
for (i = 1; i > nScores; i++)
if (min > score[i]) min = score[i];
qsort(score, nScores, sizeof(int), compare);
for (i = 0; i < nScores; i++)
cout << score[i] << ' ';
cout << "Max score = " << max << endl;
cout << "Minimum score = " << min << endl;
return 0;
}