You are on page 1of 3

Tools required: PC & Visual studio software

Code:

#include <iostream>
using namespace std;

int main()
{
int numofscores, testscores, count, t;
int match = 0;

cout << endl << "Input number of test scores to be encoded; ";
cin >> numofscores;

int a[100][2], yy;

cout << "Input the test scores;" << endl;

for (int i = 0; i<numofscores; i++)


{
cin >> a[i][0];
a[i + 1][0] = -999;
a[i][1] = 0;
}
for (int x = 0; x<numofscores; x++)
{
for (int y = 0; y<numofscores; y++)
{
if (a[y][0]>a[y + 1][0])
{
t = a[y][0];
a[y][0] = a[y + 1][0];
a[y + 1][0] = t;
}
}
}
for (int y = 0; y <= numofscores; y++)
{
if (a[y][0] == a[y + 1][0])
{
yy = y - 1;
if (yy > 0) {
while (a[yy][0] == a[y][0]) {
yy--;
}
}
yy++;
if (a[yy][1] == 0) a[yy][1]++;
a[yy][1]++;
}
else if (y > 0) {
if (a[y][0] != a[y - 1][0]) a[y][1]++;
}
else if (a[y][0] != -999) {
a[y][1]++;
}
}

cout << "Test scores Count" << endl;


for (int x = 0; x <= numofscores; x++)
{
if (a[x][1] > 0) cout << a[x][0] << " " << a[x][1] << endl;
}
}

You might also like