声明 - 再次重复它

时间:2013-10-20 18:52:31

标签: c# do-while

除了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");

2 个答案:

答案 0 :(得分:0)

我不是100%确定你要做什么,但看起来你需要将你的减速度和最大值减速到你的do循环中。

答案 1 :(得分: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");


            }