Astericks bar graph

Hi guys i have to make a programs that prompts the user to enter quiz grades and add them up. For examples the user enters 6 test grades they are out of 5 so he enters 0-5 and i store them in the array. This part works great but now i have to print out a bar of vertical asterisks for every part too. So if at the end we have one test grades that are 2 grades of 1 points, 1 grade of two point, 2 grades of three point and 1 grade of 5 point it will have to display them as this

There are 2 grades of 1
There are 1 grades of 2
There are 2 grades of 3
There are 1 grades of 5



* *
*** *
12345
Im stuck on this part any help would be appreciated i know i need to do for loops but i am stuck on what to count too and what to print i know i will need cout << "*" and a couple of spaces. Any help please thanks

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream>

using namespace std;

int main (){
    int size;
    int tests;
    int a[6]={0};
    
    cout << "How many quiz scores will you enter: ";
    cin >> size;
    
    for (int i=0; i<size; i++) {
        
    cout << "Enter quiz scores: ";
    cin >> tests;
        
        if(tests == 0)
            a[0]++;
        if(tests == 1)
            a[1]++;
        if(tests==2)
            a[2]++;
        if(tests==3)
            a[3]++;
        if(tests==4)
            a[4]++;
        if(tests==5)
            a[5]++;
        }
    for(int j=0;j<6;j++){
        cout << "There are " << a[j] << " grades of " << j << endl;
    }
    return 0;
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
int main(){
	int size;
	int tests;
	int a[6] = { 0 };

	cout << "How many quiz scores will you enter: ";
	cin >> size;

	for (int i = 0; i<size; i++) {

		cout << "Enter quiz scores: ";
		cin >> tests;

		if (tests == 0)
			a[0]++;
		if (tests == 1)
			a[1]++;
		if (tests == 2)
			a[2]++;
		if (tests == 3)
			a[3]++;
		if (tests == 4)
			a[4]++;
		if (tests == 5)
			a[5]++;
	}
	

	for (int arrayIndex = 0; arrayIndex < 6; arrayIndex++) // This loops through array
	{
		cout << "a[" << arrayIndex << "]: ";
		for (int stars = 0; stars < a[arrayIndex]; stars++) //Ouput stars
		{
			cout << "*";
		}
		cout << endl;
	}


	return 0;
}
Topic archived. No new replies allowed.