% demonstration of multiple statements in a labelled set
% declaration section
var chequing_balance : real
var menu_choice : int
var savings_balance : real
var transaction_amount : real
var money : real
% initialization section
chequing_balance := 0
savings_balance := 0
% processing section
colourback (black)
colour (white)
put " M E N U "
colourback (white)
colour (black)
put "[1] Deposit to savings"
put "[2] Deposit to chequing"
put "[3] Withdraw from savings"
put "[4] Withdraw from chequing"
put "[5] Transfer from savings to chequing"
put "[6] Transfer from chequing to savings"
put skip, "Your choice [1-6]? " ..
get menu_choice
case menu_choice of
label 1 :
put skip, " Savings deposit $" ..
get transaction_amount
savings_balance := savings_balance + transaction_amount
put skip, " New balance $", savings_balance
label 2 :
put skip, "Chequing deposit $" ..
get transaction_amount
chequing_balance := chequing_balance + transaction_amount
put skip, " New balance $", chequing_balance
label 3 :
put skip, "How much money do you have? $" ..
get money
put skip, " Withdraw$" ..
get transaction_amount
savings_balance := money - transaction_amount
put skip, " New Balance$", savings_balance
if savings_balance >= 0 then
put skip, "Thank you! "
else
put skip, "Unable to transfer! "
end if
label 4 :
put skip, "How much money do you have? $"
get money
put skip, "Chequing Withdraw$" ..
get transaction_amount
savings_balance := money - transaction_amount
put skip, " New Balance$", savings_balance
if savings_balance >= 0 then
put skip, "Thank you! "
else
put skip, "Unable to transfer! "
end if
label 5 :
put skip, "How much money do you have? $" ..
get money
put skip, " Tranfer$" ..
get transaction_amount
savings_balance := money - transaction_amount
put skip, " New Balance$", savings_balance
if savings_balance >= 0 then
put skip, "Thank you! "
else
put skip, "Unable to tranfer! "
end if
label 6 :
put skip, "How much money do you have? $" ..
get money
put skip, " Chequing$" ..
get transaction_amount
savings_balance := money+transaction_amount
put skip, " New Balance$", savings_balance
label :
put skip, "Choice must be in range 1-6."
end case
The main adjustment I made to the program was adding an if statement for the true part, that way the computer will not allow a negative number to be allowed.
No comments:
Post a Comment