Connecting Tech Pros Worldwide Forums | Help | Site Map

ATM simulation

cori25's Avatar
Member
 
Join Date: Oct 2007
Location: Milford, CT
Posts: 83
#1: Nov 3 '08
Hello,

I am creating a simulation assuming that the ATM only has $10, $20, $50 and $100 bills. I need the output to look like this:

Say the withdrawal amount is $90
Dispense: 1 - $50
2 - $20

I am having difficulty creating a function that will dispense as shown. I know that if i divide the withdrawal amount by 20 I will know how many 20's it would take for the amount but how do I distinguish which bills to use? And to have it show the number of bills needed?

Any help is appreciated.

Thanks in advance

Expert
 
Join Date: Mar 2008
Location: Naperville, Illinois U.S.
Posts: 831
#2: Nov 3 '08

re: ATM simulation


Does your simulation have a finite pool of bills to dispense? That would be more realistic, but also harder to implement.
cori25's Avatar
Member
 
Join Date: Oct 2007
Location: Milford, CT
Posts: 83
#3: Nov 3 '08

re: ATM simulation


Quote:

Originally Posted by donbock

Does your simulation have a finite pool of bills to dispense? That would be more realistic, but also harder to implement.

The max withdrawal is set to 500. I can set the simulation as I wish since the parameters were not given. This is to be a very simple source code since I have yet to learn float, cin, cout, ect.. I was thinking more along the lines of an if statement saying if it != 30, then do the amount divided by the bill but I am lost as to how to count the amount of bills as I said. Hope this makes sense. I usually can figure these out but spent 6 hrs attempting with no luck...
Member
 
Join Date: Sep 2008
Posts: 73
#4: Nov 3 '08

re: ATM simulation


sounds like bunch of conditonal statements to me. I am not sure if I understood your question, but this is the first thing that came up in my head.

Expand|Select|Wrap|Line Numbers
  1. void dispence_amount(int da)
  2. {
  3.   while(da > 0)
  4.   {
  5.     if (da > 100)
  6.     {
  7.        dispence(100);  //take from bank
  8.        hundred_bills--; //subtract # of hundred dollar bills left in ATM machine
  9.        da = da - 100;  //subtract total dispence amount left for ATM to process
  10.     }
  11.     else if(da > 50)
  12.     {
  13.        dispence(50);
  14.        fifty_bills--;
  15.        da = da - 50;
  16.     }
  17.     //and so on...
  18.   }
  19. }
  20.  
  21.  
cori25's Avatar
Member
 
Join Date: Oct 2007
Location: Milford, CT
Posts: 83
#5: Nov 3 '08

re: ATM simulation


Quote:

Originally Posted by sevak316

sounds like bunch of conditonal statements to me. I am not sure if I understood your question, but this is the first thing that came up in my head.

Expand|Select|Wrap|Line Numbers
  1. void dispence_amount(int da)
  2. {
  3.   while(da > 0)
  4.   {
  5.     if (da > 100)
  6.     {
  7.        dispence(100);  //take from bank
  8.        hundred_bills--; //subtract # of hundred dollar bills left in ATM machine
  9.        da = da - 100;  //subtract total dispence amount left for ATM to process
  10.     }
  11.     else if(da > 50)
  12.     {
  13.        dispence(50);
  14.        fifty_bills--;
  15.        da = da - 50;
  16.     }
  17.     //and so on...
  18.   }
  19. }
  20.  
  21.  

I am attempting this now but it seems like this might work. I have
#include <stdio.h>
#include <math.h>

Is there anything else to include? For dispence?
boxfish's Avatar
Expert
 
Join Date: Mar 2008
Location: California
Posts: 478
#6: Nov 3 '08

re: ATM simulation


I don't see a reason to include math.h; you would only need that for stuff like logarithms and trigonometric functions. You can probably do whatever math you need with the basic arithmetic operators.
Expert
 
Join Date: Mar 2008
Location: Naperville, Illinois U.S.
Posts: 831
#7: Nov 3 '08

re: ATM simulation


Might be some use for div or ldiv from <stdlib.h>
Needs Regular Fix
 
Join Date: Jul 2008
Posts: 385
#8: Nov 3 '08

re: ATM simulation


For each bill value starting from the largest, determine number of bills that don't exceed total amount(for the first step) or remainder( for the rest ) ( wth integer divide ), e.g. numOfBills = restAmount/100;
then calculate remainder for the next step( it will not exceed this bill value by definition )
Newbie
 
Join Date: Jun 2009
Posts: 1
#9: Jun 22 '09

re: ATM simulation


Just want to say thank you for such a wonderful information, it was really helpful!

<link removed>
Newbie
 
Join Date: Jul 2009
Posts: 1
#10: Jul 14 '09

re: ATM simulation


This is an interesting post.. thank you for sharing
Reply