Problem 34

Age Messages 3

Using if statements with compound conditions (like &&), make a program that displays a single message depending on the age given.

age            message
less than 16   "You can't drive."
16 to 17       "You can drive but not vote."
18 to 24       "You can vote but not rent a car."
25 or older    "You can do pretty much anything."

This output of this assignment is identical to the How Old Are You, Specifically assignment. However, this time you must accomplish it using if statements with compound conditions and you must not use else if or else.

Your name: Dukes
Your age: 19

You can vote but you can't rent a car, Dukes.
Your name: Dukes
Your age: 12

You can't drive, Dukes.

You can make up your own messages if you want, but you must have at least four messages, and you must use && statements to make sure only one of the messages is printed for any given age.


◄ 33: Choose Your Own Adventure! 35: Two More Questions ►



Adapted from ProgrammingByDoing.com
©2013 Graham Mitchell

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 United States License.