-2
プロシージャと関数を使用して所得税計算を作成しようとしています。コードは自明でなければなりません。すべてがゼロの値を返しています。誰かが私が間違っているところを私に少し洞察してくれますか?Visual Basicの手順と関数
Partial Class TaxCalcualtor
Inherits System.Web.UI.Page
Private totalWages As Decimal
Private taxesWithheld As Decimal
Private deductions As Integer
Private married As Boolean
Private taxLiability As Decimal
Private federalTaxes As Decimal
Private stateTaxes As Decimal
Private localTaxes As Decimal
Function SingleFunction(ByVal totalWages As Decimal, ByVal married As Boolean, ByVal taxLiability As Decimal) As Decimal
Dim taxRate As Decimal
totalWages = CDec(TextBoxWages.Text)
If married = False And totalWages < 25000.0 Then
taxRate = 0.15
ElseIf married = False And totalWages >= 25000.0 And totalWages < 45000.0 Then
taxRate = 0.18
ElseIf married = False And totalWages >= 45000.0 And totalWages < 65000.0 Then
taxRate = 0.22
ElseIf married = False And totalWages >= 65000.0 And totalWages < 85000.0 Then
taxRate = 0.28
ElseIf married = False And totalWages >= 85000.0 And totalWages < 100000.0 Then
taxRate = 0.32
ElseIf married = False And totalWages >= 100000.0 Then
taxRate = 0.35
End If
taxLiability = taxRate * totalWages
Return taxLiability
End Function
Function SingleMarriedFunction(ByVal totalWages As Decimal, ByVal married As Boolean, ByVal taxLiability As Decimal) As Decimal
Dim taxRate As Decimal
totalWages = CDec(TextBoxWages.Text)
If married = True And totalWages < 25000.0 Then
taxRate = 0.13
ElseIf married = True And totalWages >= 25000.0 And totalWages < 45000.0 Then
taxRate = 0.16
ElseIf married = True And totalWages >= 45000.0 And totalWages < 65000.0 Then
taxRate = 0.18
ElseIf married = True And totalWages >= 65000.0 And totalWages < 85000.0 Then
taxRate = 0.2
ElseIf married = True And totalWages >= 85000.0 And totalWages < 100000.0 Then
taxRate = 0.22
ElseIf married = True And totalWages >= 100000.0 Then
taxRate = 0.24
End If
taxLiability = taxRate * totalWages
Return taxLiability
End Function
Function FederalTax(ByVal taxWithheld As Decimal, ByVal taxLiability As Decimal, ByVal deductions As Integer) As Decimal
Dim federalTaxes As Decimal
taxesWithheld = CDec(TextBoxTaxesWithheld.Text)
federalTaxes = taxWithheld - taxLiability - (deductions * 750)
Return federalTaxes
End Function
Function StateTax(ByVal totalWages As Decimal) As Decimal
Dim stateTaxes As Decimal
totalWages = CDec(TextBoxWages.Text)
stateTaxes = totalWages * 0.06
Return stateTaxes
End Function
Function LocalTax(ByVal totalWages As Decimal) As Decimal
Dim localTaxes As Decimal
totalWages = CDec(TextBoxWages.Text)
localTaxes = totalWages * 0.01
Return localTaxes
End Function
Sub DisplayData()
Label7.Text += "Tax Liability: " + CStr(taxLiability)
Label7.Text += "Federal Taxes: " + CStr(federalTaxes)
Label7.Text += "State Taxes: " + CStr(stateTaxes)
Label7.Text += "Local Taxes: " + CStr(localTaxes)
End Sub
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
DisplayData()
End Sub
End Class
望ましい行動:計算税負債、連邦、州、及び地方税の問題:すべての値は、あなたが初期化されたことのない値を表示している0 – Bob
を戻ってきているが/変更します。それ以上のコードがない場合、* taxLiability *は決して変更されません。計算関数は決して呼び出されません。 – Bob
あなたは "SingleFunction"や "SingleMarriedFunction"を呼ぶことはありません。また、何も変更しないMarriedFunctionという名前にすることはできません。また、グローバル変数には、関数内で渡しているローカル変数と同じ名前を付けないでください。関数の目的は、渡された情報から値を返すことです。あなたは多くの場所で税金賦課を変更していますが、それはまた多くの場所で宣言されています。あなたはそのために混乱しています。コンピュータはあなたが本当に望む魔女を知らず、あなたにローカルのものを返します。 – Chillzy