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)
{
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);
Console.WriteLine("TotalUnits: {0}", TotalUnits);
Console.WriteLine("UnitRate: {0}", UnitRate);
Console.WriteLine("Press enter to continue"); Console.ReadLine();
Console.Clear();
} while (!SelectedOption.Equals("X") && !SelectedOption.Equals("x"));
Console.WriteLine("\n * * * All Done * * * Press \"Enter\""); Console.ReadLine();
}
static void EmployeeDetails(out string EnteredName, out decimal UnitsEarned)
{
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)
{
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;
}
static decimal CalculateUnitPayRate(decimal TotalUnits)
{
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;
}
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);
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();
}
}
}
[edit]Code block added - OriginalGriff[/edit]