単純なコードに問題があります。私がやりたいことは次のとおりです。たとえば、ユーザーが負の数のみを与え、正ではない場合、私は見たいです:
"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");