0

コードで残高を計算するのに少し問題があります。

このプログラムでは(balance = balance * (1 + interestRate)。問題は、私たちが 2013 年にいて、2015 年から 2017 年までの残高が計算されるということです。これは、ユーザーがプログラムでクリックするチェックボックスによって選択されます。また、ユーザーは、所有するアカウントの種類を選択します (つまり、貯蓄: 7% の利息法人: 5% の利息)。

次にボタンをクリックすると、選択した口座の種類 (貯蓄、法人、またはその両方)mediaEstimatedFundの残高を入力するように求められます。次に、選択した ( YearAccount、およびBalance amount )の残高を計算する必要があります。

これが私が持っているコードで、正しい残高が得られません (例: ユーザーが 2000.00 ドル、 7% の普通預金口座、2016 年を選択した場合、2621.60 ドルの推定予算が得られるはずです)。しかし、そうではありません。 !

Year     Savings Account                Corporate Account         Saving + Corporate    

2013       $2000.00                  $1000.00                   $3000.00
2014       $2140.00                  $1050.00                   $3190.00
2015       $2289.8                   $1102.5                    $3392.3
2016       $2450.086                 $1157.625                  $3607.711      
2017       $2621.59202               $1215.50625                $3837.09827

Public Class Form1

Private Sub btnMediaEstimatedFund_Click(sender As Object, e As EventArgs) Handles btnMediaEstimatedFund.Click

    Dim interestRate, initialBalanceSavings, initialBalanceCorporate, finalBalance, theYear, balance, subTotal As Double

    txtBoxEstimatedBudget.Enabled = False
    txtBoxAgenciesNeeded.Enabled = False

    If radButtonTraditional.Checked Then

        txtBoxAgenciesNeeded.Text = 3

    ElseIf radButtonEMedia.Checked Then

        txtBoxAgenciesNeeded.Text = 2

    End If

    If checkBoxSavings.Checked Then

        interestRate = 0.07

    ElseIf checkBoxCorporate.Checked Then

        interestRate = 0.05

    ElseIf checkBoxCorporate.Checked And checkBoxSavings.Checked Then

        interestRate = 0.12

    End If

    If radButton2015.Checked Then

        theYear = 2015

    End If

    If radButton2016.Checked Then

        theYear = 2016

    End If

    If radButton2017.Checked Then

        theYear = 2017

    End If

    Dim inputtedData As String

    If checkBoxSavings.Checked Then
        Do

            inputtedData = InputBox("Please enter a balance for SAVINGS account between $500.00 and $3000.00", "Initial Savings Balance", "0.00")

            If inputtedData = "" Then

                MsgBox("User chose to cancel calculation!")

                Exit Sub

            Else

                initialBalanceSavings = CType(inputtedData, Single)

                If initialBalanceSavings > 3000 Or initialBalanceSavings < 500 Then MsgBox("Please enter a balance for SAVINGS account equal to or above $500.00 and no more than $3000.00", MsgBoxStyle.Critical, "Error")

            End If

        Loop Until initialBalanceSavings >= 500 And initialBalanceSavings <= 3000

    End If

    If checkBoxCorporate.Checked Then

        Do

            inputtedData = InputBox("Please enter a balance for CORPORATE account between $500.00 and $3000.00", "Initial Corporate Balance", "0.00")

            If inputtedData = "" Then

                MsgBox("User chose to Cancel calculation!")

                Exit Sub

            Else

                initialBalanceCorporate = CType(inputtedData, Single)

                If initialBalanceCorporate > 3000 Or initialBalanceCorporate < 500 Then MsgBox("Please enter a balance for CORPORATE account equal to or above $500.00 and no more than $3000.00", MsgBoxStyle.Critical, "Error")

            End If

        Loop Until initialBalanceCorporate >= 500 And initialBalanceCorporate <= 3000

    End If

    finalBalance = initialBalanceSavings + initialBalanceCorporate

    For theYear = 2013 To 2017

        subTotal = finalBalance * (1 + interestRate)
        finalBalance = subTotal

    Next

    txtBoxEstimatedBudget.Text = FormatCurrency(finalBalance)

End Sub
4

2 に答える 2

1
For TheYear = 2013 to 2016
  SubTotal = balance * (1 + interestRate)
  balance = SubTotal
Next

アップデート

上記のコード ブロックは、ループを実行する方法と、ループ内で何を計算する必要があるかについてのアイデアを提供するためのものです。実際の答えを得るには、2013 年が現在の年であることを覚えておく必要があります。したがって、その年の利息を実際に計算することはありません。そして、これを達成する方法の鍵は、実際には次の年に開始する必要があるループのフォーマットです。

For Year = 2013 + 1 to 2016
  'blah blah blah
Next
于 2013-03-25T00:00:20.780 に答える
1

Zafs の回答を編集して余分な行を含めることは許可されていなかったので、ここに私の見解を示します。重要な点は、の初期化がfinalBalanceforループの外にあることです。

finalBalance = initialBalanceSavings + initialBalanceCorporate
For theYear = 2013 To 2016
  subtotal = finalBalance * (1 + interestRate)
  finalBalance = subTotal
Next
于 2013-03-25T09:17:02.880 に答える