在Piecework program方面需要帮助 [英] Need help with Piecework program
问题描述
我是C#的初级程序员,并且有一个项目分配项目,我必须创建一个计算薪资系统的程序。我选择了Piecework类型的工资单。我已完成前几个部分,但似乎无法获得正确的UnitPay或计算毛额,预扣税或净薪酬。下面是我现在的代码的副本(这很粗糙,因为我还在努力)。如果有人能给我帮助,我们将不胜感激。我碰到了一堵砖墙而且我自己无法通过这一点。
Hi,
I am a beginning programmer in C# and have a project for a class assignment where I have to create a program that calculates a payroll system. I choice a Piecework type payroll. I have the first few parts done, but can't seem to get it to pull up the correct UnitPay or calculate Gross, Withholdings, or Net Pay. below is a copy of my code as it is now (it is rough as I am still working on it). If anyone can give me help, it will be greatly appreciated. I have hit a brick wall and just can't get pass this point on my own.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _2ndPayrollUpgrade
{
class Program
{
static void Main(string[] args)
{
// variables
string SelectedOption;
string EmployeeName = "";
decimal TotalUnits = 0;
decimal UnitRate = 0;
do
{
Console.WriteLine(" ** PIECEWORK PAYROLL MENU **");
Console.WriteLine("A - Employee Details");
Console.WriteLine("B - Determine Rate Per Unit");
Console.WriteLine("C - Calculate Pay and Display Results");
Console.WriteLine("X - Exit");
Console.WriteLine("");
Console.Write(" Choose an option by typing the letter: ");
SelectedOption = Console.ReadLine();
if (SelectedOption.Equals("A") || SelectedOption.Equals("a"))
{ EmployeeDetails(out EmployeeName, out TotalUnits); }
else if (SelectedOption.Equals("B") || SelectedOption.Equals("b"))
{ UnitRate = CalculateUnitPayRate(TotalUnits); }
else if (SelectedOption.Equals("C") || SelectedOption.Equals("c"))
{ CalculatePayAndDisplayResults(out EmployeeName, out TotalUnits, out UnitRate); }
else if (SelectedOption.Equals("X") || SelectedOption.Equals("x"))
{ Console.WriteLine("You requested to exit"); }
else
{
Console.WriteLine("\nI got " + SelectedOption + " But I did not know what to do");
Console.WriteLine("You will have to try again");
Console.Write("Press \"Enter\" to continue"); Console.ReadLine();
}
Console.WriteLine("Name: {0}", EmployeeName); // BBM
Console.WriteLine("TotalUnits: {0}", TotalUnits); // BBM
Console.WriteLine("UnitRate: {0}", UnitRate); // BBM
Console.WriteLine("Press enter to continue"); Console.ReadLine();
Console.Clear(); // Clears screen for new input/information
} while (!SelectedOption.Equals("X") && !SelectedOption.Equals("x"));
Console.WriteLine("\n * * * All Done * * * Press \"Enter\""); Console.ReadLine();
} // End of MAIN method
static void EmployeeDetails(out string EnteredName, out decimal UnitsEarned)
{
// variables
const decimal MIN_UNITS = 1;
const decimal MAX_UNITS = 200;
Console.Clear();
Console.WriteLine("Enter Employee's Name: ");
EnteredName = Console.ReadLine();
Console.WriteLine("Enter Total Units Completed: ");
UnitsEarned = isInputGood(MIN_UNITS, MAX_UNITS);
}
static decimal isInputGood(decimal MIN, decimal MAX)
{
// variables
bool isInputGood;
bool isRangeGood = false;
decimal userInput;
do
{
Console.Write("Enter A Valid Number Between {0} and {1}: ", MIN, MAX);
isInputGood = (decimal.TryParse(Console.ReadLine(), out userInput));
if (MIN > userInput || MAX < userInput)
{ isRangeGood = false; }
if (MIN <= userInput && MAX >= userInput)
{ isRangeGood = true; }
} while (isInputGood == false || isRangeGood == false);
return userInput;
} // End of Employee Details Method
static decimal CalculateUnitPayRate(decimal TotalUnits)
{
// variable
decimal RatePerUnit = 0;
if (TotalUnits > 0 || TotalUnits <= 25) { RatePerUnit = 10.00m; }
else if (TotalUnits > 25 || TotalUnits <= 50) { RatePerUnit = 15.00m; }
else if (TotalUnits > 50 || TotalUnits <= 75) { RatePerUnit = 20.00m; }
else if (TotalUnits > 75) { RatePerUnit = 25.00m; }
return RatePerUnit;
} // End of Rate Per Unit Method
static void CalculatePayAndDisplayResults(out string EnteredName, out decimal TotalUnits, out decimal UnitRate)
{
Console.Clear();
Console.Write("Press \"Enter\" to continue");
EnteredName = Console.ReadLine();
TotalUnits = Console.Read();
UnitRate = Console.Read();
Console.WriteLine();
Console.WriteLine("Employee's Name: {0}", EnteredName);
Console.WriteLine("Total Units: {0}", TotalUnits);
Console.WriteLine("{0:$##.##}", UnitRate);
// variables
const decimal FedTaxRate = 0.12m;
const decimal SocSecRate = 0.0765m;
const decimal MedicareRate = 0.0145m;
const decimal StateTaxRate = 0.08m;
decimal GrossPay = 0;
decimal FedIncTaxWH = 0;
decimal SocSecWH = 0;
decimal MedicareWH = 0;
decimal StateIncTaxWH = 0;
decimal TotalWH = 0;
decimal NetPay = 0;
GrossPay = TotalUnits * UnitRate;
FedIncTaxWH = FedTaxRate * GrossPay;
SocSecWH = SocSecRate * GrossPay;
MedicareWH = MedicareRate * GrossPay;
StateIncTaxWH = StateTaxRate * GrossPay;
TotalWH = (FedIncTaxWH + SocSecWH + MedicareWH + StateIncTaxWH);
NetPay = GrossPay - TotalWH;
Console.WriteLine("Gross Pay : {0:$#,###.##}", GrossPay);
Console.WriteLine("FIT Withheld : {0:$#,###.##}", FedIncTaxWH);
Console.WriteLine("SS Withheld : {0:$#,###.##}", SocSecWH);
Console.WriteLine("MC Withheld : {0:$#,###.##}", MedicareWH);
Console.WriteLine("SIT Withheld : {0:$#,###.##}", StateIncTaxWH);
Console.WriteLine("NetPay : {0:$#,###.##}", NetPay);
Console.Read();
} // End of Calculate Pay and Display Results Method}
}
}
[edit]已添加代码块 - OriginalGriff [/ edit]
[edit]Code block added - OriginalGriff[/edit]
推荐答案
##。##},UnitRate);
// < span class =code-comment>变量
const decimal FedTaxRate = 0 .12m;
const decimal SocSecRate = 0 .0765m;
const 十进制 MedicareRate = 0 .0145m;
const decimal StateTaxRate = 0 跨度>0.08米;
decimal GrossPay = 0 ;
decimal FedIncTaxWH = 0 ;
decimal SocSecWH = 0 ;
decimal MedicareWH = 0 ;
decimal StateIncTaxWH = 0 ;
decimal TotalWH = 0 ;
decimal NetPay = 0 ;
GrossPay = TotalUnits * UnitRate;
FedIncTaxWH = FedTaxRate * GrossPay;
SocSecWH = SocSecRate * GrossPay;
MedicareWH = MedicareRate * GrossPay;
StateIncTaxWH = StateTaxRate * GrossPay;
TotalWH =(FedIncTaxWH + SocSecWH + MedicareWH + StateIncTaxWH);
NetPay = GrossPay - TotalWH;
Console.WriteLine( 总薪酬:{0:
##.##}", UnitRate); // variables const decimal FedTaxRate = 0.12m; const decimal SocSecRate = 0.0765m; const decimal MedicareRate = 0.0145m; const decimal StateTaxRate = 0.08m; decimal GrossPay = 0; decimal FedIncTaxWH = 0; decimal SocSecWH = 0; decimal MedicareWH = 0; decimal StateIncTaxWH = 0; decimal TotalWH = 0; decimal NetPay = 0; GrossPay = TotalUnits * UnitRate; FedIncTaxWH = FedTaxRate * GrossPay; SocSecWH = SocSecRate * GrossPay; MedicareWH = MedicareRate * GrossPay; StateIncTaxWH = StateTaxRate * GrossPay; TotalWH = (FedIncTaxWH + SocSecWH + MedicareWH + StateIncTaxWH); NetPay = GrossPay - TotalWH; Console.WriteLine("Gross Pay : {0:
#,###。##},GrossPay);
Console.WriteLine( FIT版主:{0:
#,###.##}", GrossPay); Console.WriteLine("FIT Withheld : {0:
#,###。##},FedIncTaxWH);
Console.WriteLine( SS版主:{0:
#,###.##}", FedIncTaxWH); Console.WriteLine("SS Withheld : {0:
这篇关于在Piecework program方面需要帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!