using list arrays

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?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78

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

struct test
{
  int score;
};

int compare(const void* pa, const void* pb)
  {
    const int& a = *static_cast<const int*>(pa);
    const int& b = *static_cast<const int*>(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;

  const int 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; 
}
Topic archived. No new replies allowed.