-
Histogram issues
Hey everyone how's it going I'm new here so it's nice to meet all of you. Well I have a question I'm supposed to write a histogram program where the uses inputs a set of numbers, followed by a -1. this would output a sideways histogram so for example is the use iputs 1, 2, 3, -1. the result would be
*
**
***
For some reason I can't seem to get this I've actually tried everything so this is really annoying me to be honest. I think I'm in the right directoin with the code but to be honest I think it's completely wrong. Heres my code as is
Code:
#include <iostream>
using namespace std;
void printHistogram(int ar[], int size);
int main( )
{
const int SIZE = 5;
int HistoGram[SIZE];
cout << "Enter a list of positive numbers.\n"
<< "Place a -1 at the end.\n";
int next;
cin >> next;
while (next > 0)
printHistogram(int ar[], int size)
system("pause");
return 0;
}
void printHistogram(int ar[], int size)
{
for (int i = 0; i < size; i++)
{
int numStars = ar[i];
for (int j = 0; j < numStars; j++)
cout << '*';
cout << endl;
}
}
This just creates an infinite loop of *. Anyone think they can give me some help. Anything would be greatly appreciated. Sorry if this is kind of a fairly dum question. but thanks in advanced.
-
There's no way the code you posted would compile, what with that "printHistogram(int ar[], int size)" in the middle of it all.
Were you planning to do something with the data you read in? At the moment, you're just ignoring it.