Prompt Title: New chatuhdhuadu8ad

Created 1 year ago
Votes 0
Views 85 times
0

Prompt Detail:

Sure, here's an example code in C# Windows Forms using ComboBox to calculate the total cost of attending a workshop:

csharp
private void Form1_Load(object sender, EventArgs e) { // Populate ComboBoxes cbWorkshop.Items.AddRange(new string[] { "Handling Stress", "Time Management", "Supervision Skills", "Negotiation", "How to Interview" }); cbLocation.Items.AddRange(new string[] { "Austin", "Chicago", "Dallas", "Orlando", "Phoenix", "Raleigh" }); } private void btnCalculate_Click(object sender, EventArgs e) { // Get selected workshop and location string workshop = cbWorkshop.SelectedItem.ToString(); string location = cbLocation.SelectedItem.ToString(); // Get registration fee and number of days from workshop int regFee = 0; int days = 0; switch (workshop) { case "Handling Stress": regFee = 1000; days = 3; break; case "Time Management": regFee = 800; days = 3; break; case "Supervision Skills": regFee = 1500; days = 3; break; case "Negotiation": regFee = 1300; days = 5; break; case "How to Interview": regFee = 500; days = 1; break; default: MessageBox.Show("Please select a workshop."); return; } // Get lodging fee per day from location int lodgingFee = 0; switch (location) { case "Austin": lodgingFee = 150; break; case "Chicago": lodgingFee = 225; break; case "Dallas": lodgingFee = 175; break; case "Orlando": lodgingFee = 300; break; case "Phoenix": lodgingFee = 175; break; case "Raleigh": lodgingFee = 150; break; default: MessageBox.Show("Please select a location."); return; } // Calculate total cost int totalCost = regFee + lodgingFee * days; // Display total cost MessageBox.Show($"The total cost for attending {workshop} in {location} is {totalCost:C}."); }

In this example, cbWorkshop and cbLocation are ComboBox controls in the Windows Form. The Form1_Load method is used to populate these ComboBoxes with the workshop names and location names, respectively. The btnCalculate_Click method is used to calculate the total cost when the user clicks the "Calculate" button.

The method first gets the selected workshop and location from the ComboBoxes, then uses a switch statement to look up the registration fee and number of days for the selected workshop, as well as the lodging fee per day for the selected location. It then calculates the total cost by adding the registration fee to the lodging fee multiplied by the number of days. Finally, it displays the total cost in a MessageBox.

avatar
wddw
Shared 1 prompt
Created 1 year ago

Leave a Comment