Do While

Hello I have ran into an issue I can't seem to solve. I am trying to make it so when the user types a random character thats not a number between 3 and 25, the program will cout an error and ask "Please enter the number of lines for your pyramid:". Could someone tell me what I am doing incorrectly?

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
#include <iostream>
#include <limits>

using namespace std;


void draw(int height)
{
    for(int line = 0;line<=height;line++)
    {
        int spaces = height - line;

        for(int j=1;j<=spaces;j++)
        cout<<" ";
        for(int i=1;i<=line*2+1;i++) 
        cout<<"+";
        cout<<"\n";
    }
}


int main()
{
  int height;
  do{
  cout << "\nPlease enter the number of lines for your pyramid: ";
  cin >> height;
  if(height>3 && height<25)draw(height); //Thanks to long double main

  else{
     cout << "ERROR: Please enter a value between 3 and 25!" << endl;
  }
  }while(height<3 || height>25);
  cout << "\n";

  return 0;
}


My issue is cout << "ERROR: Please enter a value between 3 and 25!" << endl; continuously loops.
Last edited on
if(height>3 || height<25)draw(height);

Can you think of any number that's not bigger than 3 OR less than 25?
Think about it.
The number 2 satisfies the second condition (< 25), while the number 100 satisfies the first (> 3).

(In other words, make it && instead of ||.)
Excellent point! Although after I made the modification I still had the same issue.
You also haven't accounted for 3 and 25.
So maybe
if(height>=3 && height<=25)draw(height);.
Topic archived. No new replies allowed.