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?
#include <iostream>
#include <limits>
usingnamespace 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.
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).