Hello -
I'm not great at programming but I'm definitely worse at maths. I have been tyring to do this 'simple' salary calculator for so long that I am getting the numbers mixed up. I have had some of the calculations adding up correctly but not others and have now reached the point that I need to be put out of my misery. Any help gratefully received ...thank you:confused:

public partial class Calculator : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void wageCalculationBut_Click(object sender, EventArgs e)
    {
        //Declare the variables
        float basicPay = 0;
        float hoursWorked = float.Parse(hoursWorkedTextBox.Text);
        float overtimePay = 0;
        float estimatedWage = 0;


        if (hoursWorked <= 40)
        switch (jobTitleRbl.SelectedIndex)//Store the basicPay 
        {

            case 0://Engineer working up to 40 hours
                basicPay = hoursWorked * 10.0F;
                break;
            case 1://Senior Engineer working up to 40 hours
                basicPay = hoursWorked * 12.0F;
                break;
            case 2://TechnicalEngineer working up to 40 hours
                basicPay = 25.0F;
                break;
            case 3://Supervisor working up to 40 hours
                basicPay = 30.0F;
                break;
        }

        //Calcluations for overtimePay 
        if (jobTitleRbl.Items[0].Selected == true && hoursWorked > 40)//Engineer
            basicPay = hoursWorked * 10.0F;
        overtimePay = (hoursWorked - 40) * 1.5F;

        if (jobTitleRbl.Items[1].Selected == true && hoursWorked > 40)//Senior Engineer
            basicPay = 12.0F * 40;
        overtimePay = (hoursWorked - 40) * 1.5F;    //18.0F

        if (jobTitleRbl.Items[2].Selected == true && hoursWorked > 40)//Technical Engineer
            basicPay = 25.0F * 40;
        overtimePay = (hoursWorked - 40) * 1.5F;// * 37.50F;

        if (jobTitleRbl.Items[3].Selected == true && hoursWorked > 40)//Supervisor
            basicPay = 30.0F * 40;
        overtimePay = (hoursWorked - 40) * 1.5F;// * 45.0F;


        //Add BEng bonus @ 10% 
        if (BEngCheckBox.Checked == true)
            basicPay = basicPay * 1.1F;

        estimatedWage = basicPay + overtimePay;
        estimatedWageLab.Text = "Your estimated wage is " + estimatedWage.ToString("c");
    }
}

Edited 5 Years Ago by johnt68: n/a

Rewrite 4 if statements with braces, start with lines 35 to 37:

if (jobTitleRbl.Items[0].Selected == true && hoursWorked > 40)//Engineer            
            {
                basicPay = hoursWorked * 10.0F;
                overtimePay = (hoursWorked - 40) * 1.5F;
            }

Err .. please ignore the last comment - I just did something typically stupid the errors are gone now! I will test it again.

Thank you very much ... it wont quite add up but most of it is heading in the right direction. I have sorted out some of the obvious mathematical idiocies that I had put in there and become blind too because I had been staring at them for too long - like forgetting to times by hours worked for two out of the four cases with basic pay!

Thanks again - I can go to bed without thinking about this now ;0)))))


:):):) I'll be putting those braces in from now on - even if visual studio does't seem to mind/

Edited 5 Years Ago by johnt68: n/a

This question has already been answered. Start a new discussion instead.