Reputation: 101
I'm trying to do the following with two check boxes. One being Medical/Dental deductions and the other a 401k deduction.
I can provide my code for the rest of my project if you'd like. I am trying to get the desired output described below. I receive this output instead of the desired one:
Name: Joe Hours: 45 Rate: 10.00 Gross Pay: $400.00 Taxes: $112.50 Net Pay: $337.50 Medical/Dental deduction: $400.00 401k deduction: $20.00
· Handle two possible pretax deductions if applicable (use two check boxes):
· Medical/dental deduction - $50.00 is deducted from gross pay if this option is selected
· 401k deduction – 5% is deducted from gross pay if this option is selected
· Tax is calculated after all deductions (25% of amount after applicable deductions)
· Include deduction amounts in the rich text box and label each amount properly
I also have to do a test case to see if it works:
· Input: hours = 45, rate 10.00, both Medical/Dental and 401k check boxes are checked · Output: gross pay = 475.00, medical/dental deduction 50.00, 401k deduction = 23.75, tax = 100.31, net pay = 300.94
I have tried to get this started, but don't know where to start. I gave it a shot and here is what I have. It's not within the check box methods, but in the calculate button method where the rest of the calculations are:
//Medical/Dental and 401k deductions...as well as tax collected.
if (MedicalDentalDeductions.Checked)
{
Gross_pay = Convert.ToInt32(HoursTextBox.Text) * decimal.Parse(RateTextBox.Text) - 50.00m;
}
if (FourOneKDeduction.Checked)
{
Gross_pay = Convert.ToInt32(HoursTextBox.Text) * decimal.Parse(RateTextBox.Text) - 0.05m * 100;
}
if ((MedicalDentalDeductions.Checked) && (FourOneKDeduction.Checked))
{ Taxes = TAX * Gross_pay; }
DisplayOutPut.Text= "Medical/Dental deduction:" + Taxes +"401k deduction:"+ Taxes;
}
Upvotes: 0
Views: 1927
Reputation: 2057
Try breaking it down into step-by-step calculation like you would do it in excel or manually -
int hours = 45;
double payRate = 10.00;
double taxRate = 0.25;
double gross = hours * payRate;
double medical = (MedicalDentalDeductions.Checked) ? 50 : 0;
double retirement = (ForOneKDeduction.Checked) ? gross * 0.05 : 0;
double pretax = gross - medical - retirement;
double tax = pretax * taxRate;
double net = gross - tax;
Upvotes: 1
Reputation: 7309
I think you want something more like this:
//Medical/Dental and 401k deductions...as well as tax collected.
decimal Gross_pay= Convert.ToInt32(HoursTextBox.Text) * decimal.Parse(RateTextBox.Text);
decimal deductionMed = 0.00m;
decimal deduction401k = 0.00m
if (MedicalDentalDeductions.Checked)
{
deductionMed = - 50.00m;
}
if (FourOneKDeduction.Checked)
{
deduction401k = Gross_pay * 0.05m;
}
Taxes = TAX * (Gross_pay -(deductionMed + deduction401k));
DisplayOutPut.Text= "Medical/Dental deduction:" + deductionMed +" 401k deduction:"+ deduction401k + "Taxes:"+Taxes ;
}
Upvotes: 1