Thread: Nested If/Else?
View Single Post
Super Moderator
Status: Offline
Posts: 250
Join Date: Dec 2012
Location: Frosno, Ca
Default 06-25-2018, 05:29 PM

Originally Posted by jkidd View Post
Hey guys -

I am working on an assignment that requires me to have a bouncer ask for the user's age. If the user is below 21, they don't get in. If the user is above 21, they're too old. If the user is indeed 21 years old, they get into the bar.

I have tried every combo that I can think of, and have read the class textbook, but can't make it work. Click on the following link to see a screenshot of my method in Alice:

Any help or advice would be great!

You have two problems with your code:
  1. age is set to 21 and never changed.
  2. The if statements need to be nested.
What you need is to first set Age to the users input and then put one if statement inside the other
    Set Age to ask user for a number
    If Age < 21 Then
        // do too young stuff
        If Age > 21 Then
            //do too old stuff
            // The user is not too young or too old
Hope this helps

Mark Henwood
Reply With Quote