Password Authentication c++

后端 未结 4 1687
野的像风
野的像风 2021-01-25 23:25

Hi this is my first time using classes so apologies for my poor explanation. Basically I am making a password function for an elevator program. LogIn is the name of my class, wh

4条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-25 23:49

    You initialize local function variable

    int attempts = 0; 
    

    so exit condition in while loop will be trigerred third times the code

     if (attempts++ ==2)
    

    is run, so you will print two times:

    while (Authenticate.getName() != Authenticate.getNameAttempt())
    {
        if (attempts++ ==2) // increment attempts
    {
        return false;
    }      
    

    It looks as it was done deliberately to exit after second print, so your confusion is hard to understand. Use the debugger, this kind of error is very easy to investigate.

提交回复
热议问题