我有一个简单的代码问题。我想做的是:例如,如果用户只给出一个负数而不是正数,那么我想看看:
"this is not valid"
Do you want to try again <y/n>?
我已经尝试了很多与 if、if else 的组合,但是我没有看到,"do you want to try again?"
或者我看到了它们和结果。
这是无效的,最大值为:0
这是不好的。
int invoer;
int max;
string repeat;
Console.WriteLine("Please give a positive number.\nIf you enter a negative number its not going to work");
do
{
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");