### 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

 ``1234567891011121314151617181920212223242526272829303132333435`` ``````#include 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> 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; }``````

 ``1234567891011121314151617181920212223242526272829303132333435363738394041`` ``````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> 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.