Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. How would I do this?

How would I do this?

Scheduled Pinned Locked Moved Visual Basic
helpquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AcadianMan
    wrote on last edited by
    #1

    I am currently taking a vb class and I am doing an exercise that involves creating a machine where people insert their money and choose a card value. The machine is suppose to give them back change. Let's say I insert 7.90 and the item costs 5.00 then the machine would give them a 2 dollar bill 3 quarters 1 dimes and 1 nickel. I am new to programming and for the life of me I can't figure out howto make VB tell howto divide up the change in this manner. It's all just printed to a pic box Any help would be appreciated. Thanks

    D T 2 Replies Last reply
    0
    • A AcadianMan

      I am currently taking a vb class and I am doing an exercise that involves creating a machine where people insert their money and choose a card value. The machine is suppose to give them back change. Let's say I insert 7.90 and the item costs 5.00 then the machine would give them a 2 dollar bill 3 quarters 1 dimes and 1 nickel. I am new to programming and for the life of me I can't figure out howto make VB tell howto divide up the change in this manner. It's all just printed to a pic box Any help would be appreciated. Thanks

      D Offline
      D Offline
      DougW48
      wrote on last edited by
      #2

      Most beginning programming and algorithm books have examples that teach how to do this. You basically start with your highest denomination change value ($5 bill maybe?) and go from there. Create a while loop while your accumulated changed is less than total change. Keep adding your current denomination until each unit is greater than your amount left to change...then go to the next lower value. When the loop ends , you'll have the exact change.

      1 Reply Last reply
      0
      • A AcadianMan

        I am currently taking a vb class and I am doing an exercise that involves creating a machine where people insert their money and choose a card value. The machine is suppose to give them back change. Let's say I insert 7.90 and the item costs 5.00 then the machine would give them a 2 dollar bill 3 quarters 1 dimes and 1 nickel. I am new to programming and for the life of me I can't figure out howto make VB tell howto divide up the change in this manner. It's all just printed to a pic box Any help would be appreciated. Thanks

        T Offline
        T Offline
        Tom John
        wrote on last edited by
        #3

        Someone posed a similar problem a while back, although not identical, it may help: http://www.codeproject.com/script/comments/forums.asp?msg=995968&forumid=1646&XtraIDs=1646&searchkw=coins&sd=11%2F28%2F2002&ed=2%2F26%2F2005#xx995884xx[^] Hope this helps Tom

        A 1 Reply Last reply
        0
        • T Tom John

          Someone posed a similar problem a while back, although not identical, it may help: http://www.codeproject.com/script/comments/forums.asp?msg=995968&forumid=1646&XtraIDs=1646&searchkw=coins&sd=11%2F28%2F2002&ed=2%2F26%2F2005#xx995884xx[^] Hope this helps Tom

          A Offline
          A Offline
          AcadianMan
          wrote on last edited by
          #4

          Thanks for the info. I am trying to do it with Mod, but it seems to be rounding the floating point. e.g. if I put Remainder = 12.6 Mod 5 then answer is rounding it to 3 and it should be 2.6 according to Microsoft. I always think of it as there are 2 fives in 12.6 which equals to 10, 12.6 - 10 with a remainder of 2.6 left over. Is this a correct assumption? Microsoft has this long calculation to explain this. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vaoprmod.asp Someone posted that there is a difference between how Visual Basic and .net perform the Mod calculation. I'm still trying to figure out how the mod thing would work within my program. Let's say there is $14.85 leftover I want to give back $5, $2, $1, , $0.25, $0.10, and $0.05 in change or bills So I assume first of all that I would need an If statement to check if the amount is above 5 dollars. i.e. Private Sub Command1_Click() Dim total As Double Dim amount As Double total = 14.85 If total > 5 Then picMain.Print total amount = total Mod 5 picMain.Print amount End If End Sub Which in theory should give me a leftover of $4.85, but when I run this it gives me 0. I can't figure out why it's not giving me at least the 4.85 or rounding it to 5 Another thing I am struggling with is what kind of code would be able to tell me how many 5's I have extracted from the 14.85? If I can figure out these two problem, then I can pretty much figure out how to do the rest. Thanks for all the help

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups