I took the liberty of posting the assignment and the work I've done. I can't figure this one out, can anyone help me
And I did put an attempt at this, almost 4 hours now and I'm burnt out. If anyone can help me I would soooo love you.
"Your app should sell tickets until the plane is full. For each customer, ask how many seats he wants to buy. If the plane has enough seats available, ask the customer to enter the name of each passenger. If the plane does not have enough seats, tell the customer how many seats are available (please see the example below).
When the plane is full, display the names of all passengers.
[Hint: Use a string array to store the names of the passengers. Create a variable to store the number of tickets sold. That will help you to decide where in the array to store each passenger’s name.]
How many seats do you need? 5
Name: Peter Chen
Name: Frank Chao
Name: Al Molin
Name: Walter Rotenberry
Name: Hong Cui
How many seats do you need? 3
Name: Witold Sieradzan
Name: Mary Orazem
Name: Hillary Paul
How many seats do you need? 4
Sorry! Only 2 seats left
How many seats do you need? 2
Name: Cindy Foster
Name: Man-Chi Leung
All seats are sold.
List of passengers:
Peter Chen
Frank Chao
Al Molin
Walter Rotenberry
Hong Cui
Witold Sieradzan
Mary Orazem
Hillary Paul
Cindy Foster
Man-Chi Leung
Press any key to continue . . .
using System;
public class Airline
{
public static void Main(string[] args)
{
int total = 10;
string[] passengers = new string[10];
int ticketsSold = 0;
for (int answer = 0; answer <= passengers.Length;)
{
Console.WriteLine("How many seats do you need? ");
ticketsSold = Convert.ToInt32(Console.ReadLine());
if (ticketsSold <= total)
{
for (int i = answer; i < ticketsSold; i++)
{
Console.Write("Name: ");
passengers[i] = Console.ReadLine();
}
total -= ticketsSold;
answer += ticketsSold;
}
else if (ticketsSold > passengers.Length)
{
Console.WriteLine("Sorry only {0} seats left", total);
}
else if (ticketsSold == passengers.Length)
{
Console.WriteLine("All seats are sold\nList of passengers:\n");
for (int x = 0; x < passengers.Length; x++)
{
Console.WriteLine("{0}", passengers[x]);
}
}
}
Console.ReadKey();
} // end Main
} // end class Airline