# Thread: Creating graphs with array

1. ## Creating graphs with array

I want my output to look like a bar graph with the number of numbers in an array in each line.

My code is not working and I don't know why.

Code:
```void graph(int a[], int lo, int hi)
{
int x,y;
for(y=(hi-1); y>=0; y--)
{
if(y%2==0)
{
cout<<setw(2)<<y<<"+";
}
else
{
cout<<setw(2)<<" "<<"|";
}
for(x=lo; x<hi; x++)
{
if(a[x]>=y)
cout<<setw(2)<<"X";
else
cout<<" ";
}
}
}```

I want it to look like the graph here p11.html

This is just my function prototype

Thanks

2. i think you need to post a bit more code, like the setw() function, does this do additional formatting, because it looks like that is all you are missing.
I just assumed some arbitrary values for your function arguments, removed the setw() and added a newline after the x loop, the Yaxis shows fine like this and the X axis is almost there

Code:
```#include<iostream>
#include<stdlib.h>

using namespace std;

const int HIGH = 19;
const int LOW = 0;

void graph(int a[HIGH], int lo, int hi)
{
int x,y;

for(y=(hi-1); y>=0; y--)
{
if(y%2==0)
{
cout <<y<<"+";
}
else
{
cout<<" "<<"|";
}
for(x=lo; x<hi; x++)
{
if(a[x]>= y)
cout<<"X";
else
cout<<" ";
}
cout << "\n";
}
}

int main()
{

int a[HIGH] = {2, 5, 9, 15, 3, 7, 12, 4, 0, 2, 14, 3, 12, 9, 6, 13, 1, 8, 3};
int lo = LOW;
int hi = HIGH;

graph(a, lo, hi);

return 0;
}```
Sure you can sort it out from there, but if you want anything like the sample you posted you should use some kind of set cursor function to accomodate all the other fields