0

私は、5000ドルのローンに対して支払われた元本と支払われた利息をプログラムに出力させようとしています。入力はすべて宣言済みです。

    Private Sub calButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calButton.Click
    Dim monthlyPayments As Double
    Dim bloanTotal As Double = 5000
    Dim rate As Double = 0.005
    Dim interest As Double
    Dim toPrincipal As Double
    Dim toInterest As Double
    Dim counter As Integer

    Do
        'calculate the montly payments.
        monthlyPayments =
    Financial.Pmt(0.06 / 12, 12, 5000)
        TextBox1.Text = monthlyPayments.ToString("C2")

        counter = counter + 1        'add one to the counter 
        interest = bloanTotal * rate    'calculate interest rate from payment that will only count as interest
        toInterest = monthlyPayments - interest 'amount of monthly payment going towards interest
        toPrincipal = monthlyPayments - toInterest ' amount of monthly payment going towards principal
        bloanTotal = bloanTotal - toPrincipal 'new balance after deducing principal from begining balance

        Label2.Text = toPrincipal.ToString & "      " &
                      toInterest.ToString &
                      ControlChars.NewLine ' concatinate principal and interest strings and create a new line


        If counter = 12 Then 'exit loop once counter has reached 12 and loan amount has reached zero
            Exit Do
        End If
    Loop
End Sub
4

1 に答える 1

0

あなたの問題は、Financial.Pmt関数が負の数を返していることだと思います。これは会計処理であるため、5000 のローンを受け取り (正の数)、支払いを行う (負の数) ことを関数に伝えています。こうすれば

monthlyPayments = Math.Abs(Financial.Pmt(0.06 / 12, 12, 5000))

その後、計算がうまくいくはずです。

于 2012-11-26T19:22:23.510 に答える