Making a & Horizontal bar Problem

Hey guys, so im having a problem of an assignment where i have to make a star bar graph. so if user input 1000 then for ever hundred in that number put a star. Wrote this code, cant really find a problem.


# include <iostream>
using namespace std;


int main()
{
int storeinp[5];
int starcal[5];

for(int a=0; a<5; a++)
{
cin>>storeinp[a];
starcal[a]=storeinp[a]/100;
}
for(int b=0; b<5; b++)
{
cout<<endl<<b+1<<":";
for(int c=1; c<=starcal[c]; c++)
cout<<"*";
}

return 0;
}

/* OUTPUT
1000
1200
800
1900
1800

1:****
2:****
3:****
4:****
5:****
--------------------------------
Process exited after 25.64 seconds with return value 0
Press any key to continue . .

*/
Last edited on
change the line for(int c=1; c<=starcal[c]; c++)

to this
for(int c=1; c<=starcal[b]; c++)
Last edited on
for(int b=0; b<5; b++)
{
cout<<endl<<b+1<<":";
for(int c=1; c<=starcal[c]; c++)
cout<<"*";
}

I think what you are doing here is, you are just printing stars.
closed account (48bpfSEw)

starcal[c]
is wrong IMHO

Thank you for solving that error.

any reason why need to put b instead of c in the loop , Confuse....

Ok. so my problem was printing a star for every array u had not the number in my array, Thx ladies and gentleman! :)
Topic archived. No new replies allowed.