How can I shorten this code with a while loop? Is it possible? cboFrom
and cboTo
is a combobox. I only know how to do simple while loops and I feel like it's a waste of time to write all the indexes and values of the combox down
public int pay;
private void Calculate_Click(object sender, EventArgs e)
{
int TheValue;
int Matatanda = int.Parse(Adults.Text);
int Bata = int.Parse(Children.Text);
int Total = Matatanda + Bata;
if (cboFrom.SelectedIndex == 0 && cboTo.SelectedIndex == 0) { TheValue = 1000; Bata = Bata * TheValue / 2; pay = (TheValue * Matatanda + Bata) * 2; }
else if (cboFrom.SelectedIndex == 0 && cboTo.SelectedIndex == 1) { TheValue = 2000; Bata = Bata * TheValue / 2; pay = (TheValue * Matatanda + Bata) * 2; }
else if (cboFrom.SelectedIndex == 0 && cboTo.SelectedIndex == 2) { TheValue = 3000; Bata = Bata * TheValue / 2; pay = (TheValue * Matatanda + Bata) * 2; }
else if (cboFrom.SelectedIndex == 0 && cboTo.SelectedIndex == 3) { TheValue = 4000; Bata = Bata * TheValue / 2; pay = (TheValue * Matatanda + Bata) * 2; }
else if (cboFrom.SelectedIndex == 0 && cboTo.SelectedIndex == 4) { TheValue = 5000; Bata = Bata * TheValue / 2; pay = (TheValue * Matatanda + Bata) * 2; }
else if (cboFrom.SelectedIndex == 0 && cboTo.SelectedIndex == 5) { TheValue = 6000; Bata = Bata * TheValue / 2; pay = (TheValue * Matatanda + Bata) * 2; }
else if (cboFrom.SelectedIndex == 0 && cboTo.SelectedIndex == 6) { TheValue = 7000; Bata = Bata * TheValue / 2; pay = (TheValue * Matatanda + Bata) * 2; }
else if (cboFrom.SelectedIndex == 0 && cboTo.SelectedIndex == 7) { TheValue = 8000; Bata = Bata * TheValue / 2; pay = (TheValue * Matatanda + Bata) * 2; }
else if (cboFrom.SelectedIndex == 0 && cboTo.SelectedIndex == 8) { TheValue = 9000; Bata = Bata * TheValue / 2; pay = (TheValue * Matatanda + Bata) * 2; }
else if (cboFrom.SelectedIndex == 0 && cboTo.SelectedIndex == 9) { TheValue = 10000; Bata = Bata * TheValue / 2; pay = (TheValue * Matatanda + Bata) * 2; }
else if (cboFrom.SelectedIndex == 0 && cboTo.SelectedIndex == 10) { TheValue = 11000; Bata = Bata * TheValue / 2; pay = (TheValue * Matatanda + Bata) * 2; }
else if (cboFrom.SelectedIndex == 0 && cboTo.SelectedIndex == 11) { TheValue = 12000; Bata = Bata * TheValue / 2; pay = (TheValue * Matatanda + Bata) * 2; }
else if (cboFrom.SelectedIndex == 0 && cboTo.SelectedIndex == 12) { TheValue = 13000; Bata = Bata * TheValue / 2; pay = (TheValue * Matatanda + Bata) * 2; }
else if (cboFrom.SelectedIndex == 0 && cboTo.SelectedIndex == 13) { TheValue = 14000; Bata = Bata * TheValue / 2; pay = (TheValue * Matatanda + Bata) * 2; }
else if (cboFrom.SelectedIndex == 0 && cboTo.SelectedIndex == 14) { TheValue = 15000; Bata = Bata * TheValue / 2; pay = (TheValue * Matatanda + Bata) * 2; }
else if (cboFrom.SelectedIndex == 0 && cboTo.SelectedIndex == 15) { TheValue = 16000; Bata = Bata * TheValue / 2; pay = (TheValue * Matatanda + Bata) * 2; }
else if (cboFrom.SelectedIndex == 0 && cboTo.SelectedIndex == 16) { TheValue = 17000; Bata = Bata * TheValue / 2; pay = (TheValue * Matatanda + Bata) * 2; }
if (cboFrom.SelectedIndex == 1 && cboTo.SelectedIndex == 0) { TheValue = 1000; Bata = Bata * TheValue / 2; pay = (TheValue * Matatanda + Bata) * 2; }
else if (cboFrom.SelectedIndex == 1 && cboTo.SelectedIndex == 1) { TheValue = 2000; Bata = Bata * TheValue / 2; pay = (TheValue * Matatanda + Bata) * 2; }
else if (cboFrom.SelectedIndex == 1 && cboTo.SelectedIndex == 2) { TheValue = 3000; Bata = Bata * TheValue / 2; pay = (TheValue * Matatanda + Bata) * 2; }
else if (cboFrom.SelectedIndex == 1 && cboTo.SelectedIndex == 3) { TheValue = 4000; Bata = Bata * TheValue / 2; pay = (TheValue * Matatanda + Bata) * 2; }
else if (cboFrom.SelectedIndex == 1 && cboTo.SelectedIndex == 4) { TheValue = 5000; Bata = Bata * TheValue / 2; pay = (TheValue * Matatanda + Bata) * 2; }
else if (cboFrom.SelectedIndex == 1 && cboTo.SelectedIndex == 5) { TheValue = 6000; Bata = Bata * TheValue / 2; pay = (TheValue * Matatanda + Bata) * 2; }
else if (cboFrom.SelectedIndex == 1 && cboTo.SelectedIndex == 6) { TheValue = 7000; Bata = Bata * TheValue / 2; pay = (TheValue * Matatanda + Bata) * 2; }
else if (cboFrom.SelectedIndex == 1 && cboTo.SelectedIndex == 7) { TheValue = 8000; Bata = Bata * TheValue / 2; pay = (TheValue * Matatanda + Bata) * 2; }
else if (cboFrom.SelectedIndex == 1 && cboTo.SelectedIndex == 8) { TheValue = 9000; Bata = Bata * TheValue / 2; pay = (TheValue * Matatanda + Bata) * 2; }
else if (cboFrom.SelectedIndex == 1 && cboTo.SelectedIndex == 9) { TheValue = 10000; Bata = Bata * TheValue / 2; pay = (TheValue * Matatanda + Bata) * 2; }
else if (cboFrom.SelectedIndex == 1 && cboTo.SelectedIndex == 10) { TheValue = 11000; Bata = Bata * TheValue / 2; pay = (TheValue * Matatanda + Bata) * 2; }
else if (cboFrom.SelectedIndex == 1 && cboTo.SelectedIndex == 11) { TheValue = 12000; Bata = Bata * TheValue / 2; pay = (TheValue * Matatanda + Bata) * 2; }
else if (cboFrom.SelectedIndex == 1 && cboTo.SelectedIndex == 12) { TheValue = 13000; Bata = Bata * TheValue / 2; pay = (TheValue * Matatanda + Bata) * 2; }
else if (cboFrom.SelectedIndex == 1 && cboTo.SelectedIndex == 13) { TheValue = 14000; Bata = Bata * TheValue / 2; pay = (TheValue * Matatanda + Bata) * 2; }
else if (cboFrom.SelectedIndex == 1 && cboTo.SelectedIndex == 14) { TheValue = 15000; Bata = Bata * TheValue / 2; pay = (TheValue * Matatanda + Bata) * 2; }
else if (cboFrom.SelectedIndex == 1 && cboTo.SelectedIndex == 15) { TheValue = 16000; Bata = Bata * TheValue / 2; pay = (TheValue * Matatanda + Bata) * 2; }
else if (cboFrom.SelectedIndex == 1 && cboTo.SelectedIndex == 16) { TheValue = 17000; Bata = Bata * TheValue / 2; pay = (TheValue * Matatanda + Bata) * 2; }
}