August 4, 2007
Hi Guys
I got following question from a book exercise. Question is given below.
2. Create a Form containing two ListBoxes. One should contain a list of baseball teams; the other should contain a list of seat types. Box seats cost $25, Grandstand seats cost $18.50, and Bleacher seats cost $10. After the user selects a team and a seat type and clicks a Button, the program should display a Label that informs the user of the selected team and the ticket price. Figure 11-21 shows the results of a typical execution. Save the file as BaseballTickets.es.
Particular string selection in the Form ListBox, for example, we say Box seat has to be represented as a $25 in the Form label. I don’t know how to implement this in the program. Please any one help.
Thank you
Posted Aug 4, 2007, 5:23 PM
Thank you very much for your help Sam. program is executing well.
SamPosted Aug 4, 2007, 5:09 PM
Hi maha,
sorry should've tested the method myself before posting
Try this:
double Price = 0; // note change
switch (((string)listBox.SelectedItem))
{
case "BoxSeat":
Price = 25;
break;
//... Other types of seat
}
label.Text = "$" + Price.ToString();
Sam.
Posted Aug 4, 2007, 5:03 PM
I tried above mention method but the program is producing following error message: Use of unassigned local variable 'Price'. I don’t know why. Please advice me.
SamPosted Aug 4, 2007, 3:10 PM
A simple switch statement should work:
i.e
double Price;
switch (((string)listBox.SelectedItem))
{
case "BoxSeat":
Price = 25;
break;
//... Other types of seat
}
label.Text = "$" + Price.ToString();
Hope this helps,
Sam.