Create the ATM simulation according to the following requirements. (1) Welcome t
ID: 641213 • Letter: C
Question
Create the ATM simulation according to the following requirements. (1) Welcome the user. (2) provide three options: (a) to withdraw money, (b) to deposit money, or (c) to check their balance. (3) For deposits and withdraws, prompt the user for an amount. (4) Display an appropriate error message if the user tries to withdraw more money than is available. (5) The account balance should update in response to the deposit/withdraw. (6) After the transaction is complete, have the program ask the user if they are finished. If yes then display the current balance, if not then the program should repeat the steps above (do not repeat the welcome).
Assume the user starts with $10,000 in the bank. The following is an example of what your command window should look like after the program has run.
Welcome to the ATM
What would you like to do (withdraw = 1, deposit = 2, check balance = 3): 2
Enter an amount to deposit: 500
Your current balance is: 10500.00
Are you finished (yes=1, no=0)? 0
What would you like to do (withdraw = 1 deposit = 2 check balance =3): 3
Your current balance is: 10500.00
Are you finished (yes=1, no=0)? 1
What would you like to do (withdraw = 1 deposit = 2 check balance =3): 1
Enter an amount to withdraw: 492814
Error. You don
Explanation / Answer
The only thing wrong with this code is that it doesn't keep the balance after each loop.
fprintf('Welcome to the ATM ')
start=10000;
withdraw=1;
deposit=2;
balance=3;
yes=1;
while yes==1;
a=input('What would you like to do:(withdraw=1,deposit=2,check balance=3) ');
if a==1
b=input('Enter an amount to withdraw ');
f=start-b;
if a==1
fprintf('Your current balance is %i ',f)
if b>start
fprintf('Error. You don''t have that much money in your account ')
end
end
elseif a==2
c=input('Enter an amount to deposit ');
if a==2
fprintf('Your current balance is %i ',start+c)
end
elseif a==3
fprintf('Your current balance is %i ',start)
else
end
yes=1;
no=0;
d=input('Are you finished:(yes=1,no=0) ');
if d==1
break
end
end
fprintf('Thank you and have a nice day. ')
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.