C# 净薪酬=总薪酬问题
我有一个非常简单的程序,可以根据用户的输入来计算总工资和净工资,我得到的净工资和总工资的数字是相同的。有人能告诉我为什么基于此不考虑税收吗?我省略了一些代码,所以它应该足够小,可以让人快速阅读C# 净薪酬=总薪酬问题,c#,C#,我有一个非常简单的程序,可以根据用户的输入来计算总工资和净工资,我得到的净工资和总工资的数字是相同的。有人能告诉我为什么基于此不考虑税收吗?我省略了一些代码,所以它应该足够小,可以让人快速阅读 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication4 {
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);
}
}
}
有人有任何意见吗?我强烈怀疑您的税收百分比
小于100
,因此您的statusTax
将0
,因为即使您想将其保存为双精度
这就是为什么你的
double netPay = grossPay - (grossPay * statusTax);
将是
double netPay = grossPay - (grossPay * 0);
及
要解决此问题,请将其中一个操作数更改为浮点值,如
double statusTax = taxPercentage / 100.0;
或
非常感谢你的帮助。这完全解决了问题。你真是天赐之物。
double statusTax = taxPercentage / 100.0;
double statusTax = (double)taxPercentage / 100;