0

除了while语句,一切都很好。如果你们能帮助我,那就太好了。当用户写“Y”再做一次时,他看到:最大值是:bla bla。

用户必须给出一个新的正数,而不是一遍又一遍地查看最大值。

Console.WriteLine("Please give a positieve number. if you enter a negatieve number its not going to work");


                int invoer = 0, max = 0;
                string repeat = "";


                do
                {

                    for (int i = 1; invoer >= 0; i++)
                    {

                        Console.Write(i + "> ");
                        invoer = int.Parse(Console.ReadLine());

                        if (max < invoer)
                        {
                            max = invoer;
                        }
                    }


                    Console.WriteLine("Maximum value is: " + max);


                    Console.WriteLine("do you want to try again? y/n: ");
                    repeat = Console.ReadLine();

                } while (repeat == "y" || repeat == "Y");
4

2 回答 2

0

我不是 100% 确定你想要做什么,但看起来你需要将你的 invover 和 max 减速移动到你的 do 循环中。

于 2013-10-20T18:57:36.690 回答
0

我在猜测这应该做什么......

   {

                //Console.WriteLine("Please give a positive number. if you enter a negative number its not going to work");

                int invoer;
                int max;
                string repeat;



                do
                {
                    //they have given a negative number and wish to try again
                    Console.WriteLine("Please give a positive number.\nIf you enter a negative number its not going to work");

                    invoer = 0;
                    max = 0;
                    repeat = "";

                    for (int i = 1; invoer >= 0; i++)
                    {

                        Console.Write(i + "> ");
                        invoer = int.Parse(Console.ReadLine());

                        if (max < invoer)
                        {
                            max = invoer;
                        }
                    }


                    Console.WriteLine("Maximum value is: " + max);


                    Console.WriteLine("do you want to try again? y/n: ");
                    repeat = Console.ReadLine();

                } while (repeat == "y" || repeat == "Y");


            }
于 2013-10-22T14:50:29.057 回答