For loop problem
Feb 8, 2011 at 2:36am UTC
Hello:D
in the code below, I am making a verticle histogram. I input an array like this 1 2 3 4 5 0 and it will print
----*
---**
--***
-****
*****
My problem is Im messing up in the Last for loops to actually print it . Please help thank you
It is not displaying anything. please help thanks in advance
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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
#include <iostream>
using namespace std;
int find_max(int values[], int size)
{
int largest = 0;
for (int i=0; i<size;i++)
{
if (values[i]>largest)
{
largest=values[i];
}
}
return largest;
}
int main()
{
const int MAX = 100;
int values[MAX];
int size = 0;
for (int i = 0; i < MAX; i++)
{
cin >> values[i];
if (values[i] == 0)
{
break ;
}
size = size + 1;
}
int largest = find_max(values, size);
//cout << "size = " << size << endl;
//cout << "largest = " << largest << endl;
for (int i = 0; i < size; i++)
{
cout << values[i] << endl;
}
// draw the chart
for (int row=0;row<size;row++)//rows
{
for (int column=0;column>=largest;--column)//columns
{
// if ( largest <= size )
{
cout <<"*i" ;
}
// else
{
cout << " " ;
}
}
cout << endl;
}
}
Feb 8, 2011 at 2:45am UTC
NEvermind got it thanks guys for lookin ;D
Topic archived. No new replies allowed.