So some of you might have seen my other thread regarding this problem. I appreciated the help I got on that issue but now I am unfortunately stuck with one more hiccup.
This program is intended to read in an array of numbers (size of the array is determined by the user). It then is to take that list, count the number of times each number is stored, sort the numbers in ascending order and print out what numbers were input and how many times each occurred. The problem i am having is that it is not supposed to repeat numbers that were entered more than once. i.e. if you enter it should ouput
Code:
1 1
2 1
3 1
4 1
5 1
but if you enter it should ouput
As you can see I have implemented unique, but it does not seem to be working. Also, my printing loop is depending on the size of the original array, which I know will not work, but I cannot figure out what else to do. Any suggestions?
Code:
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int sizeOfList=0;
int a[101] = {0};
int store[101] = {0};
int store[101] = {0};
int i;
int j=0;
cout << "Enter an integer: " << endl;
cin >> sizeOfList;
cout << "Enter an integer in the range 0-100:" << endl;
/*fills the array with user input*/
while (j < sizeOfList) {
cin >> i;
store[j] = i;
a[i]++;
j++;
}
/*Displays the values as entered*/
cout << "----------" << endl;
cout << "pre sort" << endl;
cout << "----------" << endl;
for (j = 0; j < sizeOfList; j++) {
cout << "store[" << j << "]: " << store[j] << endl;
}
cout << "----------" << endl;
/*sorts the array*/
/*sort was called from the c++ library*/
sort(store, store+j);
/*Displays the values in order*/
cout << "post sort" << endl;
cout << "----------" << endl;
for (j = 0; j < sizeOfList; j++) {
cout << "store[" << j << "]: " << store[j] << endl;
}
cout << "----------" << endl;
unique(store, store+j);
/*Displays the unique values*/
cout << "unique" << endl;
cout << "----------" << endl;
for (j = 0; j < sizeOfList; j++) {
cout << "store[" << j << "]: " << store[j] << endl;
}
cout << "----------" << endl;
/*print out*/
cout << "Entries Count" << endl;
for (j = 0; j < sizeOfList; j++) {
cout << " "<< store[j] << " ";
cout << a[i] << endl;
i++;
}
}