我有一个非常简单的程序,根据用户的输入计算毛薪和净工资,我得到的净额和总薪酬的数字是一样的。有谁能告诉我,为什么没有基于这个考虑税收?我省略了一些代码,所以它应该足够小,让人快速阅读。
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);
}
}
}有人有意见吗?
发布于 2016-01-23 20:10:12
我强烈怀疑您的taxPercentage小于100,所以您的statusTax将是0,因为即使您想要将它保存为double,也会执行整数除法。
这就是为什么你
double netPay = grossPay - (grossPay * statusTax);将会是
double netPay = grossPay - (grossPay * 0);和
double netPay = grossPay;要解决这个问题,请将您的操作数更改为浮点值,如;
double statusTax = taxPercentage / 100.0;或
double statusTax = (double)taxPercentage / 100;https://stackoverflow.com/questions/34968237
复制相似问题