454,955 Members | 1,275 Online
Need help? Post your question and get tips & solutions from a community of 454,955 IT Pros & Developers. It's quick & easy.

# ATM simulation

 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
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

 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 void dispence_amount(int da) {   while(da > 0)   {     if (da > 100)     {        dispence(100);  //take from bank        hundred_bills--; //subtract # of hundred dollar bills left in ATM machine        da = da - 100;  //subtract total dispence amount left for ATM to process     }     else if(da > 50)     {        dispence(50);        fifty_bills--;        da = da - 50;     }     //and so on...   } }     Nov 3 '08 #4

 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 void dispence_amount(int da) {   while(da > 0)   {     if (da > 100)     {        dispence(100);  //take from bank        hundred_bills--; //subtract # of hundred dollar bills left in ATM machine        da = da - 100;  //subtract total dispence amount left for ATM to process     }     else if(da > 50)     {        dispence(50);        fifty_bills--;        da = da - 50;     }     //and so on...   } }     I am attempting this now but it seems like this might work. I have #include #include Is there anything else to include? For dispence? Nov 3 '08 #5

 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 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! Jun 22 '09 #9

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