Try and Catch In Pascal

前端 未结 3 1604
甜味超标
甜味超标 2021-01-19 18:11

I\'m using Dev-Pas 1.9.2 and am trying to make sure the program doesn\'t crash when a symbol or a letter value is entered.

I\'ve googled and googled and can\'t find

3条回答
  •  孤街浪徒
    2021-01-19 18:23

    Do you really want to accept exactly four different possible inputs? (The numbers 1, 2, 3, 4, and 9) That's what you're asking for at the moment.

    Note: even with a change like the first answerer suggested, your code has a major problem. What happens if a 5 or Q is given ... you complain, AND THEN EXIT THE ROUTINE.

    In the original code, if I enter a 100, you'll print the "That was not allowed"... and then return 100 to the caller.

    Hint: loop.

    Hint 2: ensure you don't loop forever

    BTW, NEVER do: ord (some character) - 48 instead, always use: ord (some character) - ord ('0')

    Why? Two obvious reasons:

    1. readability. What's 48?

    2. correctness. If you're compiled on a non-ASCII system, 48 may not be the character code for 0.

    Stan

提交回复
热议问题