Click here to Skip to main content
15,881,709 members
Please Sign up or sign in to vote.
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 3:28am
Comments
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[^]

1 solution

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;
  }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900