15,849,996 members
1.00/5 (1 vote)
See more:
so i wanna make my program go like if i enter few numbers, in range of 0-50 51-100 it shows how many numbers are 0-50 in astricks and same for 5-100

eg i enter 23, 34,89,99,67,1,2.

i want it to be like 0-50 ****
51-100 ***

but my currently i get the asterick after i enter the number, so i i say 0-50 display *, 51-100 display !, after each number it shows the symbol instead of taking all the numbers and display the symbol the the end.

my first time actually coding so i know i am dumb.

What I have tried:

#include <iostream>

using namespace std;

int main()
{
int PSI;

for (int i =0; i<7; i++)
{
cin >> PSI;

if (PSI>=0 , PSI<=50){

cout << "*" << endl;
}
else if (PSI>=51,PSI<=100)
cout << "*" << endl;

}

return 0;
}
Posted
Updated 9-Oct-17 4:28am
Richard Deeming 10-Oct-17 12:47pm
REPOST
You have already posted this homework question:
https://www.codeproject.com/Questions/1209696/Bar-chart-Cplusplus-need-help-asap[^]

## Solution 1

You should maintain counters for range hits, e.g.
C++
```#include <iostream>
using namespace std;

int main()
{
int pres;

int inrange[2]={0};
string range[2]  = {"  0- 50 ", " 51-100 "};

for (int i =0; i<7; i++)
{
cin >> pres;
if ( (pres>= 0) && (pres <= 50) )
++inrange[0];
else if ( (pres > 50) && (pres <=100))
++inrange[1];
else
{// handle 'out of range' pressure

}
}

for (int i=0;i<2; ++i)
{
cout << range[i];
for (int j=0; j<inrange[i]; ++j)
cout << "*";
cout << endl;
}
}```