mercredi 18 septembre 2019

Switch statement not working as expected c#

I am trying to make a program that picks a different discount depending on what status the user is and how many days they are staying at a hotel, but my switch statement isn't working at all. I've tried using breaks to see where it fails, but I have had no luck.

private void BtnCompute_Click(object sender, EventArgs e)
    {
        //declaring variables
        double ratePerDay, preDiscountCost, totalCost;
        string customerStatus = (txtCustomerStatus.Text);

        //getting input from text boxes
        int days = int.Parse(txtDays.Text);
        ratePerDay = double.Parse(txtRatePerDay.Text);




        //initializing discount variable
        double discount = 0;
        //if statement to tell which discount should be applied if any.
        if (days <= 3)

        switch (customerStatus)
        {
            case "Gold":
                {
                    discount = 15 / 100;
                    break;
                }
            case "Platinum":
                {
                    discount = 20 / 100;
                    break;
                }
            default:
                {
                    discount = 0;
                    break;
                }
        }



        else if (days >= 4)

            switch (customerStatus)
            {
                case "Gold":
                    discount = 25 / 100;
                    break;

                case "Platinum":
                    discount = 30 / 100;
                    break;

                default:
                    discount = 0;
                    break;
else { 
discount = 0;
}

Aucun commentaire:

Enregistrer un commentaire