2017-09-09 57 views
0

我有一個測試即將到來,所以我試圖儘可能在書中儘可能多的問題,但我不明白爲什麼我會得到「c」作爲我的windows窗體應用程序中的輸出。如果任何人都可以幫助,我會很感激。在Visual Basic稅計算器中無法獲得輸出

Private Sub btnCompute_Click(sender As Object, e As EventArgs) Handles 
btnCompute.Click 
     Dim income, tax As Double 

     income = txtIncome.Text 

     Select Case income 
     Case Is > 9225 
      tax = income * 0.1 
     Case Is > 37450 
      tax = 922.5 + 0.15 * (income - 9225) 
     Case Is > 90750 
      tax = 5617.5 + 0.25 * (income - 37450) 
     Case Is > 189300 
      tax = 22687.5 + 0.28 * (income - 90750) 
     Case Is > 411500 
      tax = 53004 + 0.33 * (income - 189300) 
     Case Is > 413200 
      tax = 135795 + 0.35 * (income - 411500) 
     Case Is < 413200 
      tax = 144620 + 0.396 * (income - 413200) 
    End Select 

    txtTax.Text = String.Format("{0: C}", income) 
End Sub 
+0

如果將項目設置設置爲Option Strict On或者在代碼文件的第一行寫上Option Strict On,您將從編譯器獲得更多幫助,這可以使您找到正確的方法 – Fabio

+0

txtTax.Text = String.Format(「{0:C}」,income)'將停止顯示結果爲「C」。但是你確定你的代碼是正確的嗎? BC我試過了,它沒有做任何計算 – Subaz

回答

3

也許沒有空間:

txtTax.Text = String.Format("{0:C}", tax) 
1

能打到書面的唯一情況陳述> 9225和< 413200(不知道這是爲什麼即使在那裏)。您需要翻轉案例陳述的順序。

Private Sub btnCompute_Click(sender As Object, e As EventArgs) Handles btnCompute.Click 
    Dim income, tax As Double 

    income = txtIncome.Text 

    Select Case income 
     Case Is > 413200 
      tax = 144620 + 0.396 * (income - 413200) 
     Case Is > 411500 
      tax = 135795 + 0.35 * (income - 411500) 
     Case Is > 189300 
      tax = 53004 + 0.33 * (income - 189300) 
     Case Is > 90750 
      tax = 22687.5 + 0.28 * (income - 90750) 
     Case Is > 37450 
      tax = 5617.5 + 0.25 * (income - 37450) 
     Case Is > 9225 
      tax = 922.5 + 0.15 * (income - 9225) 
     Case Else 
      tax = 0.1 * income 
    End Select 

    txtTax.Text = String.Format("{0:C}", tax) 
End Sub 

此外,它看起來像你正在使用2015年稅表。你的常量沒有加起來。 (可能是我的錯)。