Back to Challenge Set 6

Code Challenge: Ride Check

Difficulty  

divider

The Brief

What they asked for
I run the coaster at the fair. Riders have to be tall enough
and old enough, but a kid who is tall enough can ride with an
adult even if they are under age. I am tired of arguing about
it, so I want the screen to say it.

Write your requirements list before you write any code. Input, calculate, output, and anything you had to decide for yourself.


Notes

  • Two conditions have to both be true for the normal case. That is one operator. The exception overrides the age rule only. That is a different one.
  • Read the brief again on the height rule. There is no exception to it. A rider who is too short cannot ride with an adult, or at any age — and whether your condition says that is the whole difficulty of this challenge.
  • Getting told no is not enough. A rider should be told which requirement they missed, which means a chain after the yes-or-no.
  • The adult question is already true or false, so read it with bool.Parse from Activity 1.11 — no conversion from text you have to spell-check.
  • Parentheses. Activity 1.15 showed that && binds tighter than ||. This brief is exactly the shape where that matters.

Sample Output

Sample Output
Height (inches): 52 [Enter]
Age: 9 [Enter]
Riding with an adult? (true/false) true [Enter]
You may ride.

Test all four of these before you submit — tall and old, tall and young with an adult, tall and young alone, and too short with an adult. The last one is where a wrong answer hides.


Submit

Your requirements list and your program file, named cc-ride-check.

Commence Challenge