Hello I am having trouble initializing all one hundred and one counters to zero when the countscores function begins.
The last function is supposed to use an outer loop that counts the possible scores, while the inner loop counts the number of occurrences of scores entered and prints an asterisk for each.
So far my program prints the possible scores and prints an asterisk next to each score. I am having difficulty making my code print the required number of asterisks dependent on the frequency of entered numbers next to each score.
This is my current code but I have manipulated this for several days only to get this some other variation or infinite loops. I am grateful for any and all help, suggestions, and advise.
This is the output I want
100 *
99
98 ****
97 **
96 ***
95 *
...
This is the output I get
100 *
99 *
98 *
97 *
96 *
95 *
...
Code:
#include <iostream>
#include <iomanip>
#include <cctype>
#include <math.h>
using namespace std;
using std::cout;
using std::cin;
const int numberOfTests = 4;
void countScores (int studentScore[][numberOfTests], int numberOfStundents, int counts[101]);
void writeHistogram (int counts[101]);
int main ()
{
int studentScore[30][numberOfTests] = {};
int counts[101] = {};
int numberOfStudents = 0;
countScores(studentScore, numberOfStudents, counts);
cout << endl;
writeHistogram(counts);
return 0;
}
void countScores (int studentScore[][numberOfTests], int numberOfStudents, int counts[101])
{
numberOfStudents = 0;
cout << "Enter the test scores (-1 to end): ";
for (int i =0; i <= numberOfTests-1; i++)
{
cin >> studentScore[numberOfStudents][i];
}
while (studentScore[numberOfStudents][0] != -1)
{
numberOfStudents++;
cout << "Enter the test scores (-1 to end): ";
for (int i = 0; i <= numberOfTests-1; i++)
{
cin >> studentScore[numberOfStudents][i];
}
}
for (int i = 0; i < numberOfStudents; i++)
{
for (int j = 0; j < studentScore[numberOfStudents][i]; j++)
return;
}
}
void writeHistogram (int counts[101])
{
for (int i = 101; i > 0; i--)
{
for (int j = 0; j <= counts[j]; j++)
{
cout << i-1 << ":";
cout << " *";
}
cout << endl;
}
return;
}