Sei sulla pagina 1di 1

MACHINE

 EXERCISE  1  –  ATM  CASH  DISPENSER  

You  are  to  create  a  program  that  simulates  how  cash  is  dispensed  in  an  ATM.  Assume  
that  the  ATM  only  has  denominations  of  P500,  P200,  and  P100.  You  are  then  to  ask  the  
user  for  an  integer  input.  Afterwards,  you  are  to  display  the  number  of  bills  per  
denomination  to  be  dispensed  by  the  ATM.  The  rule  of  thumb  in  dispensing  is  to  
dispense  as  much  of  the  larger  bills  as  possible  before  dispensing  the  smaller  ones.  After  
dispensing,  the  program  should  terminate.  

Sample  run  1:  

Enter  an  amount:  700  

You  will  receive:  

1  500  bill  

1  200  bill  

0  100  bill  

Sample  run  2:  

Enter  an  amount:  1300  

You  will  receive:  

2  500  bill  

1  200  bill  

1  100  bill  

Sidetask  1:  Add  an  ‘s’  to  the  word  ‘bill’  if  the  number  of  bills  to  be  dispensed  for  a  
particular  denomination  is  more  than  one.  

Sidetask  2:  Assume  that  the  input  may  be  invalid,  i.e.  it  would  not  be  possible  to  
dispense  the  amount  inputted.  If  so,  print  a  message  saying    “Your  input  cannot  be  
dispensed”.  Afterwards,  prompt  the  user  to  input  again.  Do  this  until  a  valid  amount  is  
inputted  and  dispensed.  

Sidetask  3:  Let  us  now  put  a  limit  on  the  number  of  available  bills  per  denomination.  
Before  getting  user  input  on  the  amount  to  be  withdrawn,  prompt  the  user  for  three  
integer  inputs  corresponding  to  the  number  of  P500,  P200,  and  P300  bills  available.    
Afterwards,  input  on  amount  to  be  withdrawn  should  be  prompted.  Your  program  
should  first  detect  if  it  can  dispense  the  input  amount  given  the  number  of  bills  of  each  
denomination.  If  not,  then  it  should  prompt  the  user  for  the  amount  to  dispense  only  
(i.e.,  do  not  prompt  the  user  for  input  on  the  number  of  bills  again).  Do  this  until  the  
input  is  no  longer  invalid,  in  which  case,  the  number  of  bills  to  be  dispensed  is  printed  
and  the  program  terminates  afterwards.  

Potrebbero piacerti anche