Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么';即使密码不';不匹配?_C#_Loops_Do While - Fatal编程技术网

C# 为什么';即使密码不';不匹配?

C# 为什么';即使密码不';不匹配?,c#,loops,do-while,C#,Loops,Do While,我的程序应该无限期地要求用户重新输入用户名和密码,直到它匹配他们的第一次输入,但是循环只运行一次。我已经切断了当用户在三次尝试中输入正确的详细信息时工作的部分,所以请不要要求我重写它,否则,此提交将无法到达更有经验的开发人员。请帮我解决这个问题,因为我真的想让这个程序运行 Console.WriteLine(“拒绝输入”); Console.WriteLine(“请重新输入您的用户名:”); 字符串username3=Console.ReadLine(); Console.WriteLine(“

我的程序应该无限期地要求用户重新输入用户名和密码,直到它匹配他们的第一次输入,但是循环只运行一次。我已经切断了当用户在三次尝试中输入正确的详细信息时工作的部分,所以请不要要求我重写它,否则,此提交将无法到达更有经验的开发人员。请帮我解决这个问题,因为我真的想让这个程序运行

Console.WriteLine(“拒绝输入”);
Console.WriteLine(“请重新输入您的用户名:”);
字符串username3=Console.ReadLine();
Console.WriteLine(“请重新输入您的密码”);
字符串password3=Console.ReadLine();
做
{
Console.WriteLine(“请再次输入您的用户名:”);
字符串username4=Console.ReadLine();
Console.WriteLine(“请再次输入您的密码”);
字符串password4=Console.ReadLine();
如果(用户名==用户名4)
{
usernamematch=true;
if(usernamematch==true)
{
如果(密码==密码4)
{
passwordmatch=true;
if(passwordmatch==true)
{
WriteLine(“此时,您将被重定向到我们的网页,但这是c#programming。”);
打破
}
其他的
{
}
}
}
}
其他的
{
}
}while(username!=username3 | | password!=password3);

这仍然有您的无限循环(不推荐),但它可以完成任务。在while循环bool中,除了“true”之外,不需要使用任何东西,因为您将使用“break;”来打破它


什么是用户名?那套怎么样?它是否应该检查username3=username4?。你能发布完整的代码吗?你正在退出while循环。取出
返回框语句。您的所有代码路径都以
返回
中断
结束,这两者都退出循环。设置
passwordmatch=true在一行,然后在下一行检查
是否(passwordmatch==true)
似乎有点不必要……我想你是个学生吧。请注意,您有一个潜在的无限循环,因为不能保证
while
条件将永远停止。更好的设计是限制尝试次数,并使用
for
循环。
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;               
    }
}