Why are you reading a value from the combobox, converting it (correctly) to an integer, then doing it again after that badly?
Try this instead:
int selectedTemp;
if (!int.TryParse(qtGuestComboBox.SelectedItem.ToString(), out selectedTemp))
{
MetroFramework.MetroMessageBox.Show(this, "Enter # of guests first", "Error parsing", MessageBoxButtons.OK);
}
else
{
if (selectedTemp >= 3)
{
...
}
}
But ... when you declare a variabel inside a set of curly brackets, that is how long it lasts - it's called
scope
{
int totalGuests += (selectedTemp -3)*5;
}
At a guess,
totalGuests
is a class level variable, so your line of code creates a new variable which "hides" the class level one. Remove the
int
and that will no longer happen:
{
totalGuests += (selectedTemp - 3) * 5;
}