净工资=总薪酬问题

时间:2016-01-23 20:04:51

标签: c#

我有一个非常简单的程序来计算基于用户输入的总薪酬和净薪酬,我得到的净薪酬和总薪酬相同。有人可以告诉我为什么不根据这个税收考虑?我省略了一些代码,所以它应该足够小,以便有人快速阅读。

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);                                       
        }
    }
}

有人有任何意见吗?

1 个答案:

答案 0 :(得分:2)

强烈怀疑您的taxPercentage小于100,因此statusTax 0因为integer division正在执行<{1}} em> even 如果你想把它保存为double

这就是你

的原因
double netPay = grossPay - (grossPay * statusTax);

将是

double netPay = grossPay - (grossPay * 0);

double netPay = grossPay;

要解决此问题,请将您的一个操作数更改为浮点值,如;

double statusTax = taxPercentage / 100.0;

double statusTax = (double)taxPercentage / 100;