Vertical bar graph

Write a program that accepts a list of up to 40 non-negative integers and displays a vertical bar graph of those values.

Number of values to graph: 5
8 4 6 3 7

#
# #
# # #
# # #
# # # #
# # # # #
# # # # #
# # # # #
---------------
8 4 6 3 7
This example graph isnt posting right its supposed to be 4 # signs above the 4 and so on.

Have everything set for my arrays and cutting array off at the right point but my loop to create the # sign graph seems to be messed up as its ony printing one line of #s and spaces.
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
42
43
  #include <iostream>
#include <iomanip>
using namespace std;

int main(){
	
	int num;
	int input;
	int size = 0;
	int array[40];
	
	cout << "Number of values to graph:";
	cin >> num;

	
		for(int i = 0; i < 40; i++){
			cin >> input;
			 if(size == (num - 1))
        {
            break;
        }
			array[i] = input;
			size++;
		}
    
    int high = array[0];
    
    for(int c = 0; c < size; c++){
    	if(array[c] > high)
    	high = array[c];
	}
    
    for(int row = high; row >= 1; row = row - 1){
    	for(int col = 0; col <= num; col++){
    		if(array[col] >= row)
    		cout << "#";
    		else
    		cout << " ";
    		
		}
	}
	
}
Last edited on
Perhaps a newline at the end of a line?
Topic archived. No new replies allowed.