我在做什么错误的数学?

我在做什么错误的数学?

问题描述:

我在做什么错误的数学?

{ 
     string EmploymentStatus = Convert.ToString(txtES.Text).ToLower(); 
     string UnionStatus = Convert.ToString(txtMS.Text).ToLower(); 
     double TotalSales = Convert.ToDouble(txtSales.Text) * 9.25; 
     double Years = Convert.ToDouble(txtYears.Text);   
     double uniondues; 
     double FICA = 0; 
     double bonus = 0; 
     double WPay = 0; 
     double TotalComission = 0; 

     if (EmploymentStatus == "full") 
     {     
      WPay = 800.00; 
     } 
     else if (EmploymentStatus == "part") 
     { 
      WPay = 200.00; 
     } 
     else 
     { 
      MessageBox.Show("Error, please enter either FULL or PART"); 
     } 

      if (UnionStatus == "member") 
      { 
       uniondues = 5.25; 
       WPay = WPay - uniondues; 
      } 
      else if (UnionStatus == "non-member") 
      { 
       uniondues = 0; 
      } 
      else 
      { 
       MessageBox.Show("Error, please enter either MEMBER or NON-MEMBER"); 
      } 
      if ((EmploymentStatus == "full") && (TotalSales > 640)) 
      { 
       bonus = TotalSales * .05; 

      } 
      else if (EmploymentStatus == "part") 
      { 
       bonus = 0; 
      } 
      if (Years >= 10) 
      { 
       TotalComission = TotalSales * .10; 

      } 
      else if (Years < 10) 
      { 
       TotalComission = TotalSales * .05; 

      } 
      else 
      { 
       MessageBox.Show("Error, please enter a valid number"); 
      } 


      FICA = WPay * .16; 
      WPay = WPay - FICA; 


     lblqWPay.Text = "The weekly pay for the employee is: " + (WPay.ToString("C")); 
     lblqTS.Text = "The total sales for this employee is: " + (TotalSales.ToString("C")); 
     lblqCom.Text = "The comission for this employee is: " + (TotalComission.ToString("C")); 
     lblqBonus.Text = "The bonus for this employee is: " + (bonus.ToString("C")); 

当我进入工作状态为“FULL”和工会的地位,“成员”,以作为“100”出售的数量,以及这些年来使用的私人无效btnDisplay_Click(对象发件人,EventArgs的)如“25”。每周的工资应该是“$ 783.30”。但我最终得到了667.59美元的产出。我看不出我做错了什么。

下面是必须遵循的准则:

全职代表在$ 20.00每小时 兼职代表每周工作20小时率每周工作四十小时的$ 10.00速度在每小时 一些代表属于工会,每周支付工会会费5.25美元 如果代表工作10年或以上,他们将获得10%的销售佣金,否则他们将获得销售额的5%的佣金 小部件售价为9.25美元 如果全职员工的销售额超过其基本工资的80%,他们有权获得销售额的5%的奖金 Al l代表根据其总收入支付16%的FICA税款

P.S.我知道这是很多阅读,但如果你能帮助我,这对我来说就像是一场圣诞奇迹。

+1

调试器?试试吧,很好。 – MarcinJuraszek 2014-12-13 02:15:38

+2

使用调试器,单步执行代码,查看每个中间结果。将每个结果与您认为在当时的正确结果进行比较。当你发现两者不一样的声明时,你已经发现了你的bug(这将在代码中或者在你的规范中)。 – 2014-12-13 02:16:55

+0

哈哈我已经试过了,我不小心将错误粘贴到论坛。 smdh。但无论如何,它仍然出现错误,我已经添加Wpay = wpay +奖金,wpay = wpay +总佣金;而最接近我得到它是784.14。 idk还有什么不对,数学是正确的。但idk – SprJD7903 2014-12-13 02:28:23

你的计算是基于关闭的工会会费...
显然,拿到783.30的薪酬,工会会费被扣除FICA税施加后...

800.00 (base) 
+ 46.25 (5% bonus when over 80% base) 
+ 92.50 (10% commission on 925 sales) 
======= 
938.75 
-150.20 (16% FICA) 
======= 
788.55 Net pay before union dues 
- 5.25 (union) 
======= 
783.30 

private void btnDisplay_Click(object sender, EventArgs e) 
{ 
    string EmploymentStatus = Convert.ToString(txtES.Text).ToLower(); 
    string UnionStatus = Convert.ToString(txtMS.Text).ToLower(); 
    double TotalSales = Convert.ToDouble(txtSales.Text) * 9.25; 
    double Years = Convert.ToDouble(txtYears.Text);   
    double uniondues = 0; 
    double FICA = 0; 
    double bonus = 0; 
    double WPay = 0; 
    double TotalComission = 0; 


    if (EmploymentStatus == "full") 
    { 
     WPay = 800.00; 
     // since already in full-time status check, compute bonus here now. 
     // based on 80% of base pay 
     if (TotalSales > WPay * .80) 
     bonus = TotalSales * .05; 
    } 
    else if (EmploymentStatus == "part") 
     WPay = 200.00; 
    else 
     MessageBox.Show("Error, please enter either FULL or PART"); 

    // Only if qualified full/part time status 
    if(WPay > 0) 
    { 
     if (UnionStatus == "member") 
     uniondues = 5.25; 
     else if (UnionStatus == "non-member") 
     uniondues = 0; 
     else 
     MessageBox.Show("Error, please enter either MEMBER or NON-MEMBER"); 

     if (Years >= 10) 
     TotalComission = TotalSales * .10; 
     else if (Years < 10) 
     TotalComission = TotalSales * .05; 
     else 
     MessageBox.Show("Error, please enter a valid number"); 


     // NOW, build out the total pay before computing FICA 
     WPay = WPay + bonus + TotalComission; 

     // NOW Compute FICA 
     FICA = WPay * .16; 

     // and remove FICA and Union dues from gross pay to get net pay 
     WPay = WPay - FICA - uniondues; 
    } 

    lblqWPay.Text = "The weekly pay for the employee is: " + (WPay.ToString("C")); 
    lblqTS.Text = "The total sales for this employee is: " + (TotalSales.ToString("C")); 
    lblqCom.Text = "The comission for this employee is: " + (TotalComission.ToString("C")); 
    lblqBonus.Text = "The bonus for this employee is: " + (bonus.ToString("C")); 
} 
+0

谢谢你,我把uniondues移到了代码的底部,现在一切都是桃色......我需要关注的细节层次是令人兴奋的。我真的不认为解决方案很简单。我真的很感谢帮助。 – SprJD7903 2014-12-13 04:36:02

+0

@ SprJD7903,不客气,就是这样,因为联邦*需要尽可能多的钱。联盟会费就像是后付款购买,工会会费的减少降低了薪酬基础,从而减少了山姆大叔的税收。 – DRapp 2014-12-13 14:18:33

根据我的计算,783.30的值是错误的。手工数学:

(800(base) - 5.25(union)+ 92.5(commision)+ 46.25(bonus))* .84(tax)= 784.14。除非薪水与您提到的指南有所不同,否则您的计划运行正常,而旧的计划错误。