**I would like the code to print out in numerical order rather than a random integer as it does at present due to the fact that I now want to fill up the bookings from 1 to the upper range of 32. Any help on this would be really appreciated, thanks in advance.
sorry if my English isn't the greatest it is not my first language!**
class FirstClassCompartment
{
public void FirstClassTickets()
{
Random rand = new Random();
bool[] seats = new bool[32];
List<int> seatsBooked = new List<int>();
int completeBooking = 0;
bool quit = false;
string ticketAmount = "";
{
Console.Clear();
Console.WriteLine("\nWelcome to the First Class booking menu");
Console.WriteLine("");
Console.WriteLine("Please enter the amount of tickets you would like to book");
ticketAmount = Console.ReadLine();
}
do
{
Console.Clear();
Console.WriteLine("\nFirst Class booking menu");
Console.WriteLine("");
Console.WriteLine("Please press 1 to complete your first class booking");
completeBooking = Int32.Parse(Console.ReadLine());
switch (completeBooking)
{
case 1:
int firstClassSeat;
if (seatsBooked.Count == 0)
{
firstClassSeat = rand.Next(32);
seats[firstClassSeat] = true;
seatsBooked.Add(firstClassSeat);
}
else
{
do
{
firstClassSeat = rand.Next(32);
if (!seatsBooked.Contains(firstClassSeat))
{
seats[firstClassSeat] = true;
}
}
while (seatsBooked.Contains(firstClassSeat) && seatsBooked.Count < 32);
if (seatsBooked.Count < 32)
{
seatsBooked.Add(firstClassSeat);
}
}
if (seatsBooked.Count >= 32)
{
Console.WriteLine("All seats for first class have been booked");
Console.WriteLine("Please press enter to continue...");
}
else
{
Console.WriteLine("Your seat: {0}", firstClassSeat + 1);
Console.WriteLine("Please press enter to continue...");
}
Console.ReadLine();
break;
default:
Console.WriteLine("ERROR: INVALID SELECTION");
quit = true;
break;
}
} while (!quit);
}
}
}
strong text
Aucun commentaire:
Enregistrer un commentaire