2017-09-09 53 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年税表。你的常量没有加起来。 (可能是我的错)。