Three Handlers for a Cash Machine
Three Handlers for a Cash Machine
The function withdrawCash(int amount) is already written. It throws a std::invalid_argument for an amount of 0 or less, a std::out_of_range for more than 500, and, like some old code does, a bare int when the amount is not a multiple of 20; otherwise it returns the amount. Write tryWithdraw(int amount) with one try and THREE handlers: on success print Dispensed: and the amount; catch std::invalid_argument and print Invalid: and its message; catch std::out_of_range and print Limit: and its message; and finally catch (...), which matches anything at all, printing Unknown error. The catch-all must come last, because handlers are tried in order and it would swallow everything placed after it.
The tests call tryWithdraw with several amounts, one line of output each.
Do NOT write a main function.
Expected Output:
Dispensed: 100 Invalid: Amount must be positive Unknown error
= newline. The output ends with a newline — print one after the last line.
Your Output
Run your code to see the output here...