I'm beggining to study C programming,so I don't know how to do basic things (may be what I do has no-sense). What I have to do is to get from the user an undefined number of integers from 1-9 and load it to an array, when the user entered 0 or 10 the loop finishes and the array was completed, so I have: int qualifications[SIZEQ] and a function to load it, it works. Now I have to calculate the frequency of each number introduced on this array. I suppose that there are a lot of ways to do it simple (I don't know any), I'm trying to do it with another array, bidimensional, with 2 rows and 10 cols, using 1 row to contain the values from 0 to 9 to compare each number to the numbers of array qualifications[]. And the other row to store the number of times that each number is present on qualifications. I don't know how to do it, I try:
// 1st row of the freq array contains the 1-9 possible qualifications
// 2nd row to count the times that every value appears in qualifications array
// example: 1st row {0,1,2,3...} if 1 repeated 3 times:
// 2nd row {0,2,0,0...}
int freq[2][10]={{0,1,2,3,4,5,6,7,8,9},{0,0,0,0,0,0,0,0,0,0}};
int j=0; //var to load 0-9 positions of freq[1][j]
for (int i = 0; i < SIZEQ; i ++)
{
if(qualifications[i]==freq[0][j]){
//what i want to do is to compare from 0 each cell of
//qual with freq with 1-9 numbers
freq[1][j] = freq[1][j] + freq[1][j];
//if detected a coincidence, increment the field of the row to
//count repetitions
//so, if qualifications[i] it's now '2' when compared to
//freq[0][2] (what it's 2) freq[1][2] it's now 1.
}
j=i;
if(j>=9){ //to avoid that j be bigger than freq column size
j=0;
}
}
j=1; //skip 0
while(j<=9){
//j print 1-9 numbers and freq[1][j] print the number of
//times it is repeated
cout << "Qualification " << j << " repeated " << freq[1][j] << " times." << endl;
j++;
}
}