namespace Payroll
{
/// <summary>
/// program of PayrollAppT10 that prompts an
/// employee for personal information including name, social
/// security number, hourly pay rate, and number of hours worked.
/// All input data is displayed. It then calculate gross pay, federal
/// and state tax witholdings, and net pay. The results are displayed to
/// the employee.
/// </summary>
class Payroll
{
// this Main method will call the PromptCalculateDisplay method
public static void Main(string[] args)
{
PromptCalculateDisplay();
}
private static void PromptCalculateDisplay()
{
// this method prompts the employee for input, display the input data,
// calculate gross pay, federal and state tax witholdings, and net pay.
// The results are displayed to the employee.
// employee input and data assignment
System.Console.Write("Enter your name: ");
string employee = System.Console.ReadLine();
System.Console.Write("Social Security number: ");
string ssn = System.Console.ReadLine();
System.Console.Write("Hourly pay rate: ");
string payRate = System.Console.ReadLine();
double currencyHourlyPayRate = System.Convert.ToDouble(payRate);
System.Console.Write("Hours worked: ");
string hours = System.Console.ReadLine();
int hoursWorked = System.Convert.ToInt32 (hours);
// data display
System.Console.WriteLine();
System.Console.WriteLine("Payroll Summary for: {0}", employee);
System.Console.WriteLine("SSN: {0}", ssn);
System.Console.WriteLine("You worked {0} hours at {1} per hour",
hoursWorked.ToString(), currencyHourlyPayRate.ToString("C"));
// calculate gross pay, witholdings, and net pay
System.Console.WriteLine();
double grossPay = hoursWorked * currencyHourlyPayRate;
System.Console.WriteLine("Grosspay: \t{0}", grossPay.ToString("C"));
const double FED_TAX = .15;
const double STATE_TAX = .05;
double fedWithholding = grossPay * FED_TAX;
double stateWithholding = grossPay * STATE_TAX;
System.Console.WriteLine("Federal withholding:\t{0}", fedWithholding.
ToString("C"));
System.Console.WriteLine("State withholding: \t{0}", stateWithholding.
ToString("C"));
double netPay = grossPay - (fedWithholding + stateWithholding);
System.Console.WriteLine("______________________________");
System.Console.WriteLine("Netpay: \t{0}", netPay.ToString("C"));
System.Console.ReadLine();
}
}
}
New code with comments:
namespace Payroll
{
/// <summary>
/// program of PayrollAppT10 that prompts an
/// employee for personal information including name, social
/// security number, hourly pay rate, and number of hours worked.
/// All input data is displayed. It then calculate gross pay, federal
/// and state tax witholdings, and net pay. The results are displayed to
/// the employee.
/// </summary>
class Payroll
{
// this Main method will call the PromptCalculateDisplay method
public static void Main(string[] args)
{
PromptCalculateDisplay();
}
private static void PromptCalculateDisplay()
{
// this method prompts the employee for input, display the input data,
// calculate gross pay, federal and state tax witholdings, and net pay.
// The results are displayed to the employee.
// employee input and data assignment
System.Console.Write("Enter your name: ");
string employee = System.Console.ReadLine();
System.Console.Write("Social Security number: ");
string ssn = System.Console.ReadLine();
System.Console.Write("Hourly pay rate: ");
string payRate = System.Console.ReadLine();
double currencyHourlyPayRate = System.Convert.ToDouble(payRate);
System.Console.Write("Hours worked: ");
string hours = System.Console.ReadLine();
int hoursWorked = System.Convert.ToInt32 (hours);
//added this code to test for overtime, but unsure if it is right and in the right place
int overTime = 0;
if (hoursWorked > 40)
overTime = (hoursWorked - 40);
int currencyOverTime = System.Convert.ToInt32(overTime); // trying to convert from string to currency
overTime = (currencyOverTime - 40);
// right here I would only like to display overtime if there is overtime, but unsure how to do it
// was considering another test condition and if there is no overtime leave it blank, but how ""
// data display
System.Console.WriteLine();
System.Console.WriteLine("Payroll Summary for: {0}", employee);
System.Console.WriteLine("SSN: {0}", ssn);
System.Console.WriteLine("You worked {0} hours at {1} per hour", payRate);
// added this line to display overtime hours
System.Console.WriteLine("You worked {0} hours overtime", overTime,
hoursWorked.ToString(), currencyHourlyPayRate.ToString("C"));
// calculate gross pay, witholdings, and net pay
System.Console.WriteLine();
double grossPay = hoursWorked * currencyHourlyPayRate;
System.Console.WriteLine("Grosspay: \t{0}", grossPay.ToString("C"));
const double FED_TAX = .15;
const double STATE_TAX = .05;
double fedWithholding = grossPay * FED_TAX;
double stateWithholding = grossPay * STATE_TAX;
System.Console.WriteLine("Federal withholding:\t{0}", fedWithholding.
ToString("C"));
System.Console.WriteLine("State withholding: \t{0}", stateWithholding.
ToString("C"));
double netPay = grossPay - (fedWithholding + stateWithholding);
System.Console.WriteLine("______________________________");
System.Console.WriteLine("Netpay: \t{0}", netPay.ToString("C"));
System.Console.ReadLine();
}
}
}