布尔数组打印语句 [英] Boolean Array Print Statement

查看:95
本文介绍了布尔数组打印语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。

我正在制作一个简单的小程序,我的程序填写了一架飞机,客户有2级1和2级,它会根据被选中的情况将该人放到现场。



到目前为止,我制作了一个有10个点的布尔飞机

我可以毫无问题地将1个人输入飞机但是在他坐下后我得到了一个无限循环?我想我可能不得不使用继续声明我觉得有一些简单的东西,我想要添加更多的人。

这里是我有什么



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

 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();

推荐答案

我不明白你的要求,但代码中发生的是,while(userchoice!= - 1)重复,因为它总是如此。在第一次迭代后,您需要将userchoice的值更改为-1。然后它将显示一次并退出循环。
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.


这篇关于布尔数组打印语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆