help on a easy c++ code

i need to make it so that the numbers will make *
so if the numbers used were 5,6,5,6,9 it would look like

*****
******
*****
******
*********

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
62
63
64
65
66
67
68
69
  int main(int argc, char** argv) {
//declare variables
int a,b,c,d,e;
float min_num = 5,max_num = 25;


cout<<"please enter a number between 5-25"<<endl;
cin>>a;
cin>>b;
cin>>c;
cin>>d;
cin>>e;


while(a < min_num || a > max_num){
cout<<"I SAID BETWEEN"<<min_num<<"and"<<max_num<<endl;
cout<<"please enter a number between 5-25"<<endl;
cin>>a;
cin>>b;
cin>>c;
cin>>d;
cin>>e;
}
while(b < min_num || b > max_num){
cout<<"I SAID BETWEEN"<<min_num<<"and"<<max_num<<endl;
cout<<"please enter a number between 5-25"<<endl;
cin>>a;
cin>>b;
cin>>c;
cin>>d;
cin>>e;
}

while(c < min_num || c > max_num){
cout<<"I SAID BETWEEN"<<min_num<<"and"<<max_num<<endl;
cout<<"please enter a number between 5-25"<<endl;
cin>>a;
cin>>b;
cin>>c;
cin>>d;
cin>>e;
}

while(d < min_num || d > max_num){
cout<<"I SAID BETWEEN"<<min_num<<"and"<<max_num<<endl;
cout<<"please enter a number between 5-25"<<endl;
cin>>a;
cin>>b;
cin>>c;
cin>>d;
cin>>e;
}

while(e < min_num || e > max_num){
cout<<"I SAID BETWEEN"<<min_num<<"and"<<max_num<<endl;
cout<<"please enter a number between 5-25"<<endl;
cin>>a;
cin>>b;
cin>>c;
cin>>d;
cin>>e;
}




return 0;
}
Last edited on
So, I see your problem.

You are trying to get input into 5 integers. You want to make sure that input is between 5 and 25. I suggest the following:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int main()
{
      int a,b,c,d,e;
      const int min_num = 5, max_num = 6; //Don't know why you used float, the input can only be int
      cout << "Please enter five numbers between " << min_num << " and " << max_num << ". Thank you.\n";
      while(!cin >> a && a >= min_num && a <= max_num)
      {
             cout << "Please enter a number between "<< min_num << " and " << max_num << ". Thank you.\n"; //Try to be more polite. Rudeness will only turn away users.
             cin.clear();
             cin.sync();
      }
      //continue in the same way, only substituting a for b and c and so on.
      //draw the asterisks
      return 0;
}


EDIT: I realized I forgot an ending quote.
Last edited on
thanks for the help

i need to have a loop on it so if they dont enter 5-25 and u say draw the asterisks but i need it so if they enter a 10 there will be 10 asterisks.


this is the problem (One interesting application of computers is drawing graphs and
bar charts (sometimes called "histograms"). Write an application that
reads up to 5 numbers (each between 5 and 25). For each number entered,
your program should draw a line containing that number of adjacent
asterisks. For example, if your program reads the number seven, it
should print *******.) my teacher said there needs to be a loop
Topic archived. No new replies allowed.