Tickets walkthrough


Write a program to compute the cost of tickets to Cthulhu's World of Goats. The worksheet looks like this to start:


The user enters the number of adult and child tickets, and whether they want goodie bags for the kids. They press the button to run the program. The program outputs the cost of the order.

Adult tickets are $15 each. Child tickets are $6. Goodie bags are $8 each. Each child gets a goodie bag, if purchased in the order.

Validate the input.

  • Adult and child tickets should be numbers, that are zero or more.
  • Goodie bags should be Y or N. Case doesn't matter. Nor do extra spaces. So " Y " is valid.
  • Children must be accompanied by at least one adult. So if there is one or more children, there should be one or more adults.

Output error messages in red, next to the input fields.

Only show error messages that apply, of course. If a value is correct, no error message should be shown for it.

Only show output (total cost) when there are no input errors.

Sample output:


Sample output rides again:


Sample output 3: This time, it's personal


Here's a walkthrough.