I'm relatively new to programming in C#. The code I am attempting to realize should provide an Array value to my variable SEAT.
private void btnFindSeat_Click(object sender, EventArgs e)
{
int AntalSaeder = int.Parse(txtbxSeats.Text);
int AntalPassagerer = int.Parse(txtbxPassengers.Text);
int[] SEATARRAY;
SEATARRAY = new int[AntalSaeder];
int RandomTal = Randomizer.Next(1, AntalSaeder);
int s = 0;
int SEAT;
listBox1.Items.Clear();
for (int i = 1; i < AntalSaeder; i++)
{
for (int j = 1; j < AntalPassagerer; j++)
{
if (AntalPassagerer > AntalSaeder)
{
MessageBox.Show("Flyet er overbooket");
}
else if (AntalPassagerer <= AntalSaeder)
{
SEAT = i + j;
}
else
{
while (AntalPassagerer <= AntalSaeder)
{
if (!SEATARRAY.Contains(RandomTal))
{
SEATARRAY[i] = RandomTal;
i++;
listBox2.Items.Add(SEATARRAY[RandomTal]);
}
SEATARRAY[s] = SEAT;
s++;
listBox1.Items.Add(SEATARRAY[RandomTal]);
}
}
}
}
}
For some reason the variable SEAT in:
SEATARRAY[s] = SEAT;
s++;
listBox1.Items.Add(SEATARRAY[RandomTal]);
Shows the error: Use of unassigned local variable. From my pov it should be assigned within the loop as SEAT = i + j;
.
I could use some help, if anyone knows what's up.