Enter the amount on deposit 100
Enter the withdrawal 50
Accepted. Balance is 50
Enter the amount on deposit 76
Enter the withdrawal 120
Refused! Balance is 76
Enter the amount on deposit 50
Enter the withdrawal 75
Overdraft! Balance is -25
1. get balance & withdrawal 1.1 get balance 1.2 get withdrawal 2. calculate resulting balance 2.1 new balance = old balance - withdrawal 3. if new balance is >= zero then 3.1 indicate transaction accepted else if new balance between zero and overdraft limit 3.2 indicate overdraft is used else 3.3 indicate transaction rejected
NAME | TYPE | Notes |
---|---|---|
overdraft_limit | INTEGER | -50 (for ease of change) |
zero | INTEGER | 0 (for readability only) |
balance | INTEGER | balance in the account |
withdrawal | INTEGER | amount requested by user |
resulting_balance | INTEGER | balance after withdrawal |
-- Fintan Culwin Sept '88 v1.0 -- program to illustrate simple selection -- b1s4p2 see text p48-49 with TEXT_IO; use TEXT_IO; procedure b1s4p2 is package int_io is new TEXT_IO.INTEGER_IO( INTEGER ); use int_io; overdraft_limit : constant INTEGER := -50; -- limit for overdraft refusal zero : constant INTEGER := 0; resulting_balance, -- result of transaction balance, -- balance in the account withdrawl : integer; -- withdrawl from the account begin -- of b1s4p2 -- get balance & withdrawal PUT ( "Enter balance of the account "); GET ( balance ); SKIP_LINE; PUT ( "Enter the withdrawal "); GET ( withdrawl ); SKIP_LINE; -- calculate resulting balance resulting_balance := balance - withdrawl; -- decide upon action if resulting_balance >= zero then PUT ( "Accepted balance is "); PUT ( resulting_balance ); NEW_LINE; elsif resulting_balance >= overdraft_limit then PUT ( "Overdraft balance is "); PUT ( resulting_balance ); NEW_LINE; else PUT ( "Refused balance is "); PUT ( balance ); NEW_LINE; end if; end b1s4p2;