ATM simulation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cori25
    New Member
    • Oct 2007
    • 83

    ATM simulation

    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
  • donbock
    Recognized Expert Top Contributor
    • Mar 2008
    • 2427

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

    Comment

    • cori25
      New Member
      • Oct 2007
      • 83

      #3
      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...

      Comment

      • sevak316
        New Member
        • Sep 2008
        • 73

        #4
        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.

        Code:
        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...
          }
        }

        Comment

        • cori25
          New Member
          • Oct 2007
          • 83

          #5
          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.

          Code:
          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 <stdio.h>
          #include <math.h>

          Is there anything else to include? For dispence?

          Comment

          • boxfish
            Recognized Expert Contributor
            • Mar 2008
            • 469

            #6
            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.

            Comment

            • donbock
              Recognized Expert Top Contributor
              • Mar 2008
              • 2427

              #7
              Might be some use for div or ldiv from <stdlib.h>

              Comment

              • newb16
                Contributor
                • Jul 2008
                • 687

                #8
                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 )

                Comment

                • kakanguyen
                  New Member
                  • Jun 2009
                  • 1

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

                  <link removed>
                  Last edited by Frinavale; Jun 22 '09, 08:27 PM. Reason: Please do not post any links to sites that are not helpful in solving the problem. Link removed: spam.

                  Comment

                  • lindapret88
                    New Member
                    • Jul 2009
                    • 1

                    #10
                    This is an interesting post.. thank you for sharing
                    Last edited by Frinavale; Jul 14 '09, 02:17 PM. Reason: Please do not post any links to sites that are not helpful in solving the problem. Link removed: spam.

                    Comment

                    Working...