A more OOP approach to your question and also removing the problem of parsing the input text is the following:
First create a class Beverage
public class Beverage
{
public string Description {get;set;}
public decimal Price {get;set;}
public override string ToString()
{
return $"{this.Description} {(this.Price != 0 ? this.Price.ToString("C") : "")}";
}
}
now create a List<Beverage>
with your data
List<Beverage> drinks = new List<Beverage>()
{
new Beverage {Description = "", Price = 0m},
new Beverage {Description = "Soda", Price = 1.95m},
new Beverage {Description = "Tea", Price = 1.50m},
new Beverage {Description = "Coffee", Price = 1.25m},
new Beverage {Description = "Mineral Water", Price = 2.95m}
};
comboBoxBeverage.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxBeverage.DataSource = drinks;
Now you can retrieve a Beverage instance from your combobox instead of a string and you get the Price directly from this Beverage instance
private void Button1_Click(object sender, EventArgs e)
{
if(comboBoxBeverage.SelectedItem != null)
{
Beverage b = comboBoxBeverage.SelectedItem as Beverage;
SubTotal += b.Price;
labelSubtotal.Text = SubTotal.ToString("C");
}
}
This solution works because the ComboBox calls ToString() for every item added to its list through the DataSource property unless you set the DisplayMember and ValueMember properties.
Also notice that when dealing with currency values you should use the decimal type, not the double type