16Legal Driving Age

You can test for equality, but you may need to test to see how a number compares to a known value and display a message if the number is too low or too high.

Write a program that asks the user for their age and compare it to the legal driving age of sixteen. If the user is sixteen or older, then the program should display “You are old enough to legally drive.” If the user is under sixteen, the program should display “You are not old enough to legally drive.”

Example Output

 
What is your age? 15
 
You are not old enough to legally drive.

Or

 
What is your age? 35
 
You are old enough to legally drive.

Constraints

  • Use a single output statement.

  • Use a ternary operator to write this program. If your language doesn’t support a ternary ...

Get Exercises for Programmers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.