473,378 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

ATM simulation

cori25
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 5064
donbock
2,426 Expert 2GB
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
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
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
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
469 Expert 256MB
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
donbock
2,426 Expert 2GB
Might be some use for div or ldiv from <stdlib.h>
Nov 3 '08 #7
newb16
687 512MB
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
Just want to say thank you for such a wonderful information, it was really helpful!

<link removed>
Jun 22 '09 #9
This is an interesting post.. thank you for sharing
Jul 14 '09 #10

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

Similar topics

1
by: Steaming Balturd | last post by:
are there any php based economic simulations out there - not trading games per se, but more like simulating an economy, be it running a business or running a government? All i've been able to...
0
by: Constandinos Mavromoustakis | last post by:
Dear all, first we apologize if you receive multiple copies of this announcement. please see below if you are interested. Thank you in advance....
2
by: Samir Patel | last post by:
For last couple of weeks, I was doing lot of research on various simulation libraries. Only one I find in python is http://simpy.sourceforge.net. It is very powerful, but it seems that it does not...
0
by: Constandinos Mavromoustakis | last post by:
http://agent.csd.auth.gr/~cmavrom -------------------------------------------------- ============================================================================ = 37th Annual Simulation...
0
by: Gus | last post by:
---------------------------------------------------------------------------- ------------------------------------ Call for Papers: 38th Annual Simulation Symposium Part of the 2005 Spring...
19
by: Nicolas Pernetty | last post by:
Hello, I'm looking for any work/paper/ressource about continuous system simulation using Python or any similar object oriented languages (or even UML theory !). I'm aware of SimPy for...
1
by: Daryl Shanley | last post by:
I have some c code that writes results directly to a file as they're produced during a simulation. I want to modify the code to write directly to a postgres database using libpq. I think I could...
0
by: Karatza Helen | last post by:
Our apologies if you have received multiple copies -------------------------------------------------- Call for Papers: 38th Annual Simulation Symposium Part of the 2005 Spring Simulation...
1
by: Tim Silva | last post by:
SDX Modeling, Simulation and Numerical Computing Environment for science and engineering has now been released. Major features include: * A unified simulation environment for modeling virtually...
4
by: Richard Blackwood | last post by:
Hello all. I have a few questions about simulation programming. One, do all programmers know to how to code a simulation? By simulation I mean a model of real world relationships (i.e. like...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.