You are to program part of the interface for a simple ATM. When the user inserts their card
and types the correct PIN (you do NOT have to write this part of the program), the system
will place the users’ checking account balance in a variable CBal and the users’ savings
account balance in SBal .
You are to write a function that will accept SBal and CBal as inputs and return two
variables NewCBal and NewSBal containing the checking and savings balances after the
transaction is completed. The function should do the following:
■ Display a menu titled “Main Menu” with the following three options.
• Get cash
• Get balance
• Quit
■ If “Get cash” is selected, another menu titled “Withdrawal amount” with the following
four items is displayed:
• $20
• $60
• $100
• $200
■ After selecting an amount, a menu titled “From which account?” should be displayed
showing the following two options:
• Checking
• Savings
■ At this point, the program should verify that the selected account contains sufficient
funds for the requested withdrawal.
■ If not, a message should be displayed that says: “Sorry. You do not have sufficient funds
in your SSSS account to withdraw $XX” where SSSS is either Savings or Checking and
$XX is the selected withdrawal amount.
■ If funds are available, the program should call a function named Disp20(x), where x is
the number of $20 bills to dispense. (See note about Disp20 below.) After that, the
withdrawal amount should be subtracted from the appropriate balance.
■ After processing the “Get cash” request, the program should return to the main menu.
Note About Disp20(x): The purpose of this function is to dispense the requested
number of $20 bills—that is, to shove x bills out of the slot in the ATM machine. This
does not really exist, since we do not have an ATM machine to work with. Thus, if you
try to run your code, you will get an error (“Undefined function . . .”).
In order to test your program, add the following function to your current path:
function[]=Disp20(x)
fprintf('%.0f $20 bills were dispensed.\n',x)
where x is the number of bills to be dispensed.
This allows you to know if the program reached the proper location in the code. It
is fairly common in software development to use a “dummy” function in the place of a
real one when the device to be controlled has not been completed or is not available in
order to help verify whether the software is reaching the correct places in the code for
various situations.
■ If “Get Balance” is selected, another menu titled “Which account?” should appear with
the two choices:
• Checking
• Savings
and the program should then display “Your SSSS balance is $bb.bb.,” where SSSS is
either Savings or Checking and $bb.bb is the balance in the selected account.
■ After processing the “Get balance” request, the program should return to the main
menu.
■ If Quit is selected, the function should return to the calling program with the updated
balances in NewCBal and NewSBal . Note that the new balances will be equal to the
original balances if no money was drawn from an account, but they must still be returned
in the two new balance variables.