Friday, February 3, 2012

Chapter 4 troubles

The color selection program went smoothly, now working on the workshop selector which is giving some problems. I know there has got to be an easier way than turning this thing into a Rude Goldberg Machine. Here is a sample of the code I have so far
        
private void btn_Calculate_Click(object sender, EventArgs e)
        {
            string workshop; // To hold the workshop
            string location;     // To hold the location
            double registrationcost; // To hold the Registration Cost
            double numberofdays; // To hold Number of Days
            double lodgingFees; // To hold Lodging Fees
            double totlodging; // to hold the total Lodging Fees
            double totalcost;  // To hold Total Cost

            if (list_Workshop.SelectedIndex != -1)
            {
                // Get the Workshop Selected
                workshop = list_Workshop.SelectedItem.ToString();

                // Determine the Regeistration Fee and Number of Days
                switch (workshop)
                {
                    case "Handling Stress":
                        registrationcost = 1000;
                        numberofdays = 3;
                        lbl_Registration_Cost.Text = registrationcost.ToString("c");
                        if (list_Location.SelectedIndex != -1)
                        {
                            // Get the Location to Figure out cost
                            location = list_Location.SelectedItem.ToString();

                            // Determine the Location
                            switch (location)
                            {
                                case "Austin":
                                    lodgingFees = 150;
                                    totlodging = lodgingFees * numberofdays;
                                    totalcost = totlodging + registrationcost;
                                    lbl_Lodging_Cost.Text = totlodging.ToString("c");
                                    lbl_Total_Cost.Text = totalcost.ToString("c");
                                    break;
                            }
                        }
                        break;
I was trying to incorporate the switch element, so far it works ok but having to include a switch for each case seems to make this code a lot longer than it should be, any help is appreciated

2 comments:

  1. Im going in a different approach. But I'm also going for the long way. Whatever I do, I'm still can't think of a way to make the coding shorter.

    ReplyDelete
  2. I'm working in it right now and I am a little stuck too. :( Good luck to you guys too!

    ReplyDelete