Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/473.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 修复在输入的用户输入循环与其在数组中的索引匹配之前不继续的用户输入_C# - Fatal编程技术网

C# 修复在输入的用户输入循环与其在数组中的索引匹配之前不继续的用户输入

C# 修复在输入的用户输入循环与其在数组中的索引匹配之前不继续的用户输入,c#,C#,我遇到的问题是,当我从数组中输入一个元素时,用户输入会重置到循环的开始,例如,当我从数组中输入第三个元素时,用户输入问题会再重复两次以继续下一个用户输入问题,我如何解决这个问题?大家都知道我在这里可以调整什么。 while(true) { 字符串[]bgtype={“奶酪汉堡”、“tlc”、“bbq”}; int[]bgtyperprice={15,25,10}; int max=bgtype.Length; 字符串[]产品=新字符串[max]; 字符串[]类型=新字符串[max]; 整数[]

我遇到的问题是,当我从数组中输入一个元素时,用户输入会重置到循环的开始,例如,当我从数组中输入第三个元素时,用户输入问题会再重复两次以继续下一个用户输入问题,我如何解决这个问题?大家都知道我在这里可以调整什么。

while(true)
{
字符串[]bgtype={“奶酪汉堡”、“tlc”、“bbq”};
int[]bgtyperprice={15,25,10};
int max=bgtype.Length;
字符串[]产品=新字符串[max];
字符串[]类型=新字符串[max];
整数[]数量=新整数[最大值];
int[]disc=新的int[max];
控制台。写线(“”);
对于(int i=0;i
if(bgtype[i].Contains(type[i]))
应更改为
if(bgtype.Contains(type[i])
Array.Contains,验证项目是否包含在数组中,而不是数组值中。通过询问
bgtype[i]
是否包含
type[i]
,您是在询问
cheesburger
是否包含
tlc
,而它不包含
tlc
,因此为什么它从一开始就开始了。通过验证
bgtype
是否包含
type[i]
,您会询问
[“cheesburger”、“tlc”、“bbq”]
是否包含
tlc
,它确实包含。我希望这足够清楚。

那么,关于。。
        while (true)
        {
            String[] bgtype = { "cheeseburger","tlc", "bbq" };
            int[] bgtypeprice = { 15, 25, 10 };
            int max = bgtype.Length;
            String[] product = new string[max];
            String[] type = new string[max];
            int[] qty = new int[max];
            int[] disc = new int[max];

            Console.WriteLine("");

            for (int i = 0; i < max; i++)
            {
                Console.Write("What PRODUCT would you like to buy ?: "); ;
                product[i] = Console.ReadLine();
                if (product[i].Equals("burger", StringComparison.CurrentCultureIgnoreCase))
                {
                    {
                        Console.Write("What TYPE of product would you like to buy?: ");
                        type[i] = Console.ReadLine();
                        if (bgtype[i].Contains(type[i]))
                        {
                            Console.Write("Enter your discount % (5% for adults & 7% for minors): ");
                            disc[i] = Convert.ToInt32(Console.ReadLine());

                            Console.Write("How many will you buy? ");
                            qty[i] = Convert.ToInt32(Console.ReadLine());

                            float total = bgtypeprice[i]; total *= qty[i];
                            Console.WriteLine("Total cost of " + type[i] + " " + product[i] + " is: " + qty[i] + " pieces x P" + bgtypeprice[i] + "= P" + total);
                            float totaldisc = 0; totaldisc = (total * disc[i]) / 100;
                            Console.WriteLine("Total amount of discount: P " + totaldisc);
                            float totalamt = 0; totalamt = total - totaldisc;
                            Console.WriteLine("Total cost of order: P " + totalamt);
                            Console.WriteLine("-------------------ORDER CONFIRMATION-------------------");
                            }}}}}