Hey guys, I'm new to these forums and new to C++ in general. I have been looking around the forums and I have found threads with similar issues to mine but unfortunately they don't cover my exact issue. Essentially I want to make a histogram in C++ that takes a series of numbers that the user enters and then creates a histogram out of the ranges. I have made some progress on my own however I am stumped at the moment. Here is my code
#include <iostream>
using namespace std;
int bin_array [3];
int i;
int j;
int data;
int main()
{
cin >> grade;
if (data>=1 && data<9) {bin_array[0]++; }
else if (data>10 && data<19) {bin_array[1]++; }
else if (data>20 && data<29) {bin_array[2]++; }
else if (data>30 && data<39) {bin_array[3]++; }
cout << "1-9: ";
for (i=0;i<bin_array[j];i++) {cout << "*" << endl; }
return 0;
}
as you can see I have managed to code it so the input can be sorted into one of four different ranges, and I can perform an output for when a user enters a value between 1 and 9. What I would like to do however is code it so the user can enter multiple numbers until the user enters 40 and then display the histogram accordingly so it would come out with something like this:
1-9: ***
10-19: *
20-29: **
30-39: ****
I appreciate any help that can be given :)