← Back to Exceptions
Question 761
Ticket Order With Two Kinds of Error
Ticket Order With Two Kinds of Error
Write a function ticketTotal(int count) that returns the price of count tickets as an int at 12 each. Two things can go wrong, and each gets its own exception type:
- count below 1: throw a std::invalid_argument with the message Count must be at least 1
- count above 10: throw a std::out_of_range with the message At most 10 tickets per order
Both types live in <stdexcept>. The tests call ticketTotal for several counts, each in its own try with two catch blocks, printing Total: and the price, Invalid: and the message, or Limit: and the message, one line per count.
Do NOT write a main function.
Expected Output:
Total: 36 Invalid: Count must be at least 1 Total: 120
= newline. The output ends with a newline — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
Exceptions
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.