Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello all.
I am working on a small simple program my program fills up a air plane with customers there is 2 levels 1 and 2 and it will put that person in the spot depending on being picked.

So far i made a boolean airplane with 10 spots
I can enter 1 person into the airplane with no problem but then after he sits down i get a infinite loop? I assume i maybe have to use the continue statement I feel like there is something simple that im missing i want to add more people.
here is what i have

C#
 class Program
02
    {
03
        static void Main(string[] args)
04
        { bool[] planeSeats = {false, false, false, false, false, false, false, false, false, false };
05
            //Display random little information about the airline "welcome mesasge"
06
            Console.WriteLine("-- Welcome to the Airline System --");
07
            for (int i = 1; i < planeSeats.Length+1; i++)
08
            {
09
                Console.Write("Seat" + i + "\t");                 
10
            }
11
            for (int i = 0; i < planeSeats.Length; i++)
12
            {
13
                if (planeSeats[i] == false)
14
                {
15
                    System.Console.Out.Write("A"+"\t");
16
                }
17
                else
18
                {
19
                    System.Console.Out.Write("O" + "\t");
20
                }   //Console.Write(planeSeats[i] + "\t");
21
            }
22
            //Determine weather the user presses 1 for first class, 2 for economy, -1 for exit
23
            Console.WriteLine("Please type 1 for First Class");
24
            Console.WriteLine("Please type 2 for Economy");
25
            Console.WriteLine("Please type -1 to Exit");
26
            int userChoice = Convert.ToInt32(Console.ReadLine());
27
            Console.WriteLine("choice: " + userChoice);
28
 
29
            Boolean seatOpen = false;
30
            Boolean seatTaken = true;
31
            Random r = new Random();
32
            int seatNumber;
33
            seatNumber = r.Next(0, 5);
34
 
35
            if (seatTaken)
36
            {
37
                while (userChoice != -1)
38
                {
39
                    if (userChoice == 1)
40
                    {
41
                        for (int i = 0; i < 6 && seatOpen == false; i++)
42
                        {
43
                            planeSeats[seatNumber] = true;
44
                            //r.
45
                            //planeSeats[seatNumber] = true;
46
                            //Console.WriteLine("
47
                        }
48
                        //FirstClass();
49
                        for (int i = 1; i < planeSeats.Length + 1; i++)
50
                        {
51
                            Console.Write("Seat" + i + "\t");
52
                        }
53
                        for (int i = 0; i < planeSeats.Length; i++)
54
                        {
55
                            if (planeSeats[i] == false)
56
                            {
57
                                System.Console.Out.Write("A" + "\t");
58
                            }
59
                            else
60
                            {
61
                                System.Console.Out.Write("O" + "\t");
62
                            }   //Console.Write(planeSeats[i] + "\t");
63
                        }
64
                        Console.ReadLine();
Posted
Comments
TheBigBearNow 20-Feb-14 0:45am    
how do i make another lap to put another customer in a seat? i am trying to fill up the airplane

1 solution

Iam not understand your requirement but what happening in your code is, While(userchoice!=-1) was repeating because it always true. you need to change the value of userchoice to -1 after the first iteration. Then it will displays one time and exits the loop.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900