jeudi 24 septembre 2015

IF statement issues in C#

I've made a small speed citation form for my class that calculates predetermined fields and adds them to the users speed.

For example, if the user selects visitor the minimum citation is #25 dollars if the infraction happened at night their is an additional $25 dollar penalty. If student is selected the citation is #35 + additional $2 per every mile over, unless Sophomore is selected than it becomes $5.

Unfortunately, IF statements are my bane and I've made a mistake with my IF statements because my math isn't coming out correctly. If I select a student + night + 25 in a 20 that total should equal 70 and I am getting 10.

GUI Image: http://ift.tt/1iNLfOL

  private void Processbutton_Click(object sender, EventArgs e)
    {
        double visitorFine = 35;
        double studentFine = 45;
        double facultyFine = 55;
        double ticketPrice;
        double nightFine = 25;
        double sophomoreOver;
        double freshmenOver;
        double speedLimit = 25;


        sophomoreOver = double.Parse(SpeedtextBox.Text) - speedLimit * 5;
        freshmenOver = double.Parse(SpeedtextBox.Text) - speedLimit * 2;


        //Find the price
        if (VisitorRB.Checked)
        {
            ticketPrice = visitorFine;
        }
        else if (StudentRB.Checked)
        {
            ticketPrice = studentFine;
        }
        else if (FSRB.Checked)
        {
            ticketPrice = facultyFine;
        }
        else
        {
            ticketPrice = studentFine;
        }

        //Find and add special night fines
        if (NightCB.Checked)
        {
            ticketPrice = nightFine + ticketPrice;
        }

        // sop or soph

        if (SophCB.Checked)
        {
            ticketPrice = ticketPrice + sophomoreOver;
        }
        else
        {
            ticketPrice = ticketPrice + freshmenOver;
        }


        PricetextBox.Text = ticketPrice.ToString("C");
    }

Aucun commentaire:

Enregistrer un commentaire