I have been trying to get this to function. I however seem to be re displaying the array rather than it given me a count of each number. so for instance the array is populated by 1,2, 2,4,7,9, 9, 9, 11, 12 , 13, 13 , 15, 16, 16 , 16, 16, 19, 20
it will display
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
|
| Number | Count |
----------------------------------
| 20 | 20 |
| 19 | 19 |
| 18 | 16 |
| 17 | 16 |
| 16 | 16 |
| 15 | 16 |
| 14 | 15 |
| 13 | 13 |
| 12 | 13 |
| 11 | 12 |
| 10 | 11 |
| 9 | 13 |
| 8 | 9 |
| 7 | 9 |
| 6 | 9 |
| 5 | 7 |
| 4 | 4 |
| 3 | 2 |
| 2 | 2 |
| 1 | 1 |
---------------------------------- |
What it should display however is:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
|
| Number | Count |
----------------------------------
| 20 | 1 |
| 19 | 1 |
| 18 | 0 |
| 17 | 0 |
| 16 | 4 |
| 15 | 1 |
| 14 | 0 |
| 13 | 2 |
| 12 | 1 |
| 11 | 1 |
| 10 | 0 |
| 9 | 3 |
| 8 | 0 |
| 7 | 1 |
| 6 | 0 |
| 5 | 0 |
| 4 | 1 |
| 3 | 0 |
| 2 | 2 |
| 1 | 1 |
---------------------------------- |
1 2 3 4 5 6
|
void display_frequency(const int number_list[])
{
for(int i=20;i > 0; i--)
cout << "\t" << "|"<< setw(8) << i << setw(9)<< "|" << setw(8)
<< number_list[i]<< setw(8) << "|" << endl;
}
|
my random generator to populate the array is:
1 2 3 4 5 6 7
|
void load_array(int number_list[])//populate the array
{
int x=0;
srand ((unsigned)time(0));
for(int x = 0; x < SIZE; x++)
number_list[x]=(rand() % 20+1); // 1-20
}
|
I would like to point out I am not using classes or anything to that effect. this is rather simple in practice I am just missing something