2016-01-23 79 views
1

我有一个非常简单的程序,由用户来计算基于输入总量和净工资,我得到净重和毛重付出同样的数字。谁能告诉我,为什么在此基础上的税收不被考虑?我省略了一些代码,所以它应该是足够小,有人快速读取。净工资=工资总额的问题

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 

namespace ConsoleApplication4 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      Console.WriteLine("Enter tax percentage: 23 for divorced, 13 for                widowed, 15 for married, 22 for single"); 
      taxPercentage = Int16.Parse(Console.ReadLine()); 

      double statusTax = taxPercentage/100; 
      Console.WriteLine("Enter amount of overtime hours earned"); 
      overtimeHours = Convert.ToDouble(Console.ReadLine()); 
      overtimeRate = 1.5; 
      double overtimePay = overtimeHours * overtimeRate; 
      double grossPay = overtimePay + normalPay; 
      double netPay = grossPay - (grossPay * statusTax); 
      Console.WriteLine("Gross Pay is"); 
      Console.WriteLine(grossPay); 
      Console.WriteLine("Net pay is"); 
      Console.WriteLine(netPay);          
     } 
    } 
} 

任何人有任何输入?

回答

2

强烈怀疑你taxPercentage小于100所以你statusTax会因为执行甚至integer division0,如果你想将其保存为double

这就是为什么你

double netPay = grossPay - (grossPay * statusTax); 

double netPay = grossPay - (grossPay * 0); 

double netPay = grossPay; 

为了解决这个问题,改变你的操作数的一个浮点值等;

double statusTax = taxPercentage/100.0; 

double statusTax = (double)taxPercentage/100; 
+0

非常感谢你的帮助。这完全解决了这一问题。你是天赐之物。 –