I want to prompt user for range to print something but if it user puts negative or more 8 to reprompt.
1 Answer
Think negatively!
Look at the test that the code is doing:
while(n <= 8 && n >= 1 )
This checks that n is in the range that is valid. You want the loop to repeat if it isn't in the range. So, you need a test for the opposite.
Two ways to do that. Either negate the test :
while( !(n <= 8 && n >= 1) )
or check for the opposite:
while(n > 8 || n < 1 )
If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)
-
thank you so much it worked . what does !() exclamation next to private mean . thanks for your time Commented Oct 7, 2022 at 14:30
-
The "!" exclamation is the logical NOT operator. Google it.– Cliff BCommented Oct 7, 2022 at 18:16