帮助换回($ 1,$ 5,$ 10,$ 20,Q,D,N和Pennies)

时间:2010-09-16 23:51:32

标签: math vb6

嘿大家,任何人都可以帮我解决这个功能中的美元问题。它做的变化很好,但它确实所有的金额变回我想要大笔账单(1美元,5美元,10美元和20美元)的美元和Q /的变化d / N / p的。

Dim Quarters As Integer
Dim Dimes As Integer
Dim Nickels As Integer
Dim Pennies As Integer

Sub GetChange(ByVal Amount As Currency, ByRef Quarters As Integer, ByRef Dimes As Integer, ByRef Nickels As Integer, ByRef Pennies As Integer)
Dim Cents As Integer

   Cents = Amount * 100
   Quarters = Cents \ 25
   Cents = Cents Mod 25
   Dimes = Cents \ 10
   Cents = Cents Mod 10
   Nickels = Cents \ 5
   Pennies = Cents Mod 5

End Sub

Call GetChange(5.56, Quarters, Dimes, Nickels, Pennies)

任何帮助都会很棒! :O)

更新,已解决

Private Sub theUSChange(Amount)
    Dim USCurrency(9) As Currency
    Dim USCurrencyNames(9) As Currency
    Dim Amount As Currency
    Dim Result As Currency
    Dim I As Integer

    USCurrencyNames(0) = " Pennies: "
    USCurrency(0) = 0.01
    USCurrencyNames(1) = "   Dimes: "
    USCurrency(1) = 0.05
    USCurrencyNames(2) = " Nickles: "
    USCurrency(2) = 0.1
    USCurrencyNames(3) = "Quarters: "
    USCurrency(3) = 0.25

    USCurrencyNames(4) = "      $1: "
    USCurrency(4) = 1
    USCurrencyNames(5) = "      $5: "
    USCurrency(5) = 5
    USCurrencyNames(6) = "     $10: "
    USCurrency(6) = 10
    USCurrencyNames(7) = "     $20: "
    USCurrency(7) = 20
    USCurrencyNames(8) = "     $50: "
    USCurrency(8) = 50
    USCurrencyNames(9) = "    $100: "
    USCurrency(9) = 100

    For I = UBound(USCurrency) To LBound(USCurrency) Step -1
        Do While Amount >= USCurrency(I)
            Amount = Amount - USCurrency(I)
            Result = Result + 1
        Loop
        Debug.Print(USCurrencyNames(I) & Result)
        Result = 0
    Next
End Sub

call theUSChange(5.77)

OUTPUT:
    $100: 0
     $50: 0
     $20: 0
     $10: 0
      $5: 1
      $1: 0
Quarters: 3
 Nickles: 0
   Dimes: 0
 Pennies: 2

大卫

2 个答案:

答案 0 :(得分:1)

只需为账单添加值即可。你已经有了一个开始。

答案 1 :(得分:0)

此问题在Concrete Mathematics中使用生成函数作为示例得出。