Joined

·
933 Posts

Ok, what the program does is take the input values, put them in order, and count how many copies of each value there is. It then outputs those results. By looking at the code, I just don't understand what the heck is going on. I'm kinda having trouble grasping the whole multi-dimensional array thing too.

Code:

Code:

```
#include <iostream>
#include <iomanip>
using namespace std;
const int ARRAY_SIZE=100;
void processData(int twoDim[][2], int& len, int size);
void sortTwoDim(int twoDim[][2], int len);
void print(int twoDim[][2], int len);
int main()
{
int numList[ARRAY_SIZE][2];
int length;
processData(numList, length, ARRAY_SIZE);
sortTwoDim(numList, length);
print(numList, length);
return 0;
}
void processData(int twoDim[][2], int& len, int size)
{
int num;
bool found;
int i;
len=0;
system("cls");
cout << "Enter a maximun of 100 positive integers ending with -999" <<endl;
cin >> num;
while(num != -999 && len < size)
{
found = false;
for (i= 0; i < len; i++)
if(num == twoDim[i][0])
{
found= true;
break;
}
if(!found)
{
twoDim[len][0]=num;
twoDim[len][1]=1;
len++;
}
else
twoDim[i][1]++;
cin >> num;
}
}
void sortTwoDim(int twoDim[][2], int len)
{
int ind;
int mInd;
int smallInd;
int temp;
for(ind= 0; ind < len-1; ind++)
{
smallInd=ind;
for(mInd=ind+1; mInd < len; mInd++)
if(twoDim[smallInd][0] > twoDim[mInd][0])
smallInd=mInd;
temp=twoDim[smallInd][0];
twoDim[smallInd][0]=twoDim[ind][0];
twoDim[ind][0]=temp;
temp=twoDim[smallInd][1];
twoDim[smallInd][1]=twoDim[ind][1];
twoDim[ind][1]=temp;
}
}
void print(int twoDim[][2], int len)
{
int i, j;
system("cls");
cout << setw(7) << "Test Score" << " " << setw(6) << "Count" <<endl;
for(i= 0; i < len; i++)
{
for(j= 0; j < 2; j++)
cout << setw(6) << twoDim[i][j] << " ";
cout <<endl;
}
}
```