CJCoding With Joseph
15free / daySign inCreate account

Bad Quantity Error Carries the Value

An exception can carry data about what went wrong. Complete BadQuantityError, which inherits from std::exception and keeps the rejected quantity in its private int quantity:

- a constructor BadQuantityError(int q) that stores q - const char* what() const noexcept override returning Quantity must be between 1 and 50 - int getQuantity() const returning the stored value

Then write orderBoxes(int quantity): when the quantity is below 1 or above 50 throw a BadQuantityError built from it; otherwise print Ordered , the quantity and boxes.

The tests order several quantities, printing Error: , the message and the rejected value in parentheses after (got when the order fails.

Do NOT write a main function.

Expected Output:

Ordered 10 boxes
Error: Quantity must be between 1 and 50 (got 0)
Error: Quantity must be between 1 and 50 (got 51)
Ordered 50 boxes

= newline. The output ends with a newline — print one after the last line.

Hints4 available
Topics:
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.