Title. I'm working on a vertical bar graph program, and it doesn't work.
What it should print:
Code:
Number of values to graph: 3
1 2 3
#
# #
# # #
---------
1 2 3
What it does print:
Code:
Enter number of numbers here: 3
1
2
3
------------
# 1 # 2 # 3
Can someone help me fix this? My code is:
Code:
#include <iostream>
using namespace std;
int main ( ) {
int num;
int array[40];
cout << "Enter number of numbers here: ";
cin >> num;
for(int i = 0; i < num; i++) {
cin >> array[i];
}
int largest = array[0];
// for(int i = 0; i < num; i++) {
// cin >> array[i];
// }
for (int i = 0; i < num; i++) {
if (array[i] > largest) {
largest = array[i];
}
}
// for(int cond = 0; cond <= 5; cond++){
// if(array[cond] > largest) {
// largest = array[cond];
// }
for (int rows = largest; rows <= largest; rows++) {
for(int columns = 0; columns <= 5; columns++){
// else {
cout << " ";
// }
}
cout << endl;
}
for(int columns = 0; columns <= 5; columns++) {
cout << "--";
}
cout << endl;
for(int columns = 0; columns < num; columns++){
// if(array[columns] >= rows) {
cout << "# ";
// }
cout << array[columns] << " ";
// cout << "The largest (should be): " << largest;
}
cout << endl;
}
I hope someone can help!