我的程序应该无限地要求用户重新输入用户名和密码,直到它与他们的第一个输入匹配为止,但是循环仅运行一次。当用户在3次尝试中输入正确的详细信息时,我已经切断了该部分的工作,因此请不要让我重写它,否则,此提交内容将无法覆盖更有经验的开发人员。请帮我解决此问题,因为我真的想让该程序运行。
Console.WriteLine("Entry denied");
Console.WriteLine("Please re-enter your username:");
string username3 = Console.ReadLine();
Console.WriteLine("Please re-enter your password");
string password3 = Console.ReadLine();
do
{
Console.WriteLine("Please re-enter your username once more:");
string username4 = Console.ReadLine();
Console.WriteLine("Please re-enter your password once more");
string password4 = Console.ReadLine();
if (username == username4)
{
usernamematch = true;
if (usernamematch == true)
{
if (password == password4)
{
passwordmatch = true;
if (passwordmatch == true)
{
Console.WriteLine("You, at this point, would be redirected to our webpage but this is c# programming.");
break;
}
else
{
}
}
}
}
else
{
}
} while (username != username3 || password != password3);
答案 0 :(得分:0)
这仍然有您的无限循环(不建议使用),但可以完成工作。在while循环布尔中,除了“ true”以外,不需要使用其他任何东西,因为您将使用“ break;”来打破它。
Console.WriteLine("Entry denied");
Console.WriteLine("Please re-enter your username:");
string username3 = Console.ReadLine();
Console.WriteLine("Please re-enter your password");
string password3 = Console.ReadLine();
while (true)
{
Console.WriteLine("Please re-enter your username once more:");
string username4 = Console.ReadLine();
Console.WriteLine("Please re-enter your password once more");
string password4 = Console.ReadLine();
usernamematch = username == username4;
passwordmatch = password == password4;
if (usernamematch && passwordmatch)
{
Console.WriteLine("You, at this point, would be redirected to our webpage but this is c# programming.");
break;
}
}