By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,955 Members | 1,275 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,955 IT Pros & Developers. It's quick & easy.

ATM simulation

cori25
P: 83
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
Nov 3 '08 #1
Share this Question
Share on Google+
9 Replies


Expert 100+
P: 2,415
Does your simulation have a finite pool of bills to dispense? That would be more realistic, but also harder to implement.
Nov 3 '08 #2

cori25
P: 83
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...
Nov 3 '08 #3

P: 73
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.  
Nov 3 '08 #4

cori25
P: 83
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?
Nov 3 '08 #5

boxfish
Expert 100+
P: 469
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.
Nov 3 '08 #6

Expert 100+
P: 2,415
Might be some use for div or ldiv from <stdlib.h>
Nov 3 '08 #7

100+
P: 687
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 )
Nov 3 '08 #8

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

<link removed>
Jun 22 '09 #9

P: 1
This is an interesting post.. thank you for sharing
Jul 14 '09 #10

Post your reply

Sign in to post your reply or Sign up for a free account.