Hello,
I thought that I had sorted this a while back - but testing with fresh eyes has revealed otherwise.
I think everything works (of course I may be quite deluded) but if the tick box is checked and a calculation is made it adds 10% - which is good but if it is unchecked that figure just stays there and messes the whole thing up which is bad, and returns silly numbers - as well as making a mockery of the ridiculous amount of time I have spent on this 'thing'
I have tried if elses, ifs etc ... (checkboox.Checked == false) and even (checkboox.Checked != true) I have twisted and turned and now my head is aching, I'm hungry, and would be grateful for any suggestions. Please don't credit me with any intellegence - my brain has gone numb. Thank you.
Here is the offending artile.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
// This wage calculator asks the user to enter whether or not they hae a BEng certificate,
// the hours they have worked and their job title. The results are displayed
public partial class WageCalculator : System.Web.UI.Page
{
protected void wageCalculationBut_Click(object sender, EventArgs e)
{
//Declare the variables
float basicPay = 0;
float hoursWorked = float.Parse(hoursWorkedTextBox.Text); //so the float can be accessed from the text box
float overtimePay = 0;
float estimatedWage = 0;
float BEngBonus = 0;
float BEngBasicBonus = 0;
float BEngOvertimeBonus = 0;
if ((jobTitleRbl.Items[0].Selected && hoursWorked <= 40) || (jobTitleRbl.Items[1].Selected && hoursWorked <= 40) || (jobTitleRbl.Items[2].Selected && hoursWorked <= 40) || (jobTitleRbl.Items[3].Selected && hoursWorked <= 40))
switch (jobTitleRbl.SelectedIndex)//Store the basicPay
{
case 0://Engineer working up to 40 hours
basicPay = 10.0F * hoursWorked;
break;
case 1://Senior Engineer working up to 40 hours
basicPay = 12.0F * hoursWorked;
break;
case 2://TechnicalEngineer working up to 40 hours
basicPay = 25.0F * hoursWorked;
break;
case 3://Supervisor working up to 40 hours
basicPay = 30.0F * hoursWorked;
break;
}
else
{
//Calcluations for overtimePay
if (jobTitleRbl.Items[0].Selected == true && hoursWorked > 40)//Engineer working over 40 hours
{
basicPay = 10.0F * 40;
overtimePay = (hoursWorked - 40) * 15.0F; //£15 oT per hour
}
if (jobTitleRbl.Items[1].Selected == true && hoursWorked > 40) //Senior Engineer working over 40 hours
{
basicPay = 12.0F * 40;
overtimePay = ((hoursWorked - 40) * 18.0F); //£18 oT per hour
}
if (jobTitleRbl.Items[2].Selected == true && hoursWorked > 40) //Technical Engineer working over 40 hours
{
basicPay = 25.0F * 40;
overtimePay = (hoursWorked - 40) * 37.5F; //£37.50 oT per hour
}
if (jobTitleRbl.Items[3].Selected == true && hoursWorked > 40)//Supervisor working over 40 hours
{
basicPay = 30.0F * 40;
overtimePay = (hoursWorked - 40) * 45.0F;//£45.00 oT per hour
}
}
//Add BEng bonus @ 10%
if (BEngCheckBox.Checked == true)
{
BEngBasicBonus = basicPay * 1.1F;
BEngOvertimeBonus = overtimePay * 1.1F;
BEngBonus = (BEngBasicBonus + BEngOvertimeBonus) - (basicPay + overtimePay);
BEngLab.Text = "BEng. Bonus = " + BEngBonus.ToString("c");//show if check box checked
}
basicPayLab.Text = "Basic Pay = " + basicPay.ToString("c");
estimatedWage = basicPay + overtimePay + BEngBonus;
estimatedWageLab.Text = "Your estimated wage is " + estimatedWage.ToString("c");
if (hoursWorked > 40)
{
overtimePayLab.Text = "Overtime Pay = " + overtimePay.ToString("c");
}
if(hoursWorked <= 40)
{
overtimePayLab.Text = " " ;
}
}
}
.