0

Basically what the program is suppose to do is verify that the username that was entered (in previous code to register) matches the username that is inputted right now. So the user is allowed 3 chances to get it correct, but instead the code is not breaking out of the loop. Can anyone see what is wrong/needs fixing?

//User Enters username, and then username is verified

    do
        { 

            Console.Write("Please enter your username: ");
            user_login = Console.ReadLine();


            if (user_login != username)
            {
                Console.WriteLine("The username does not match the one in our database");
                Console.WriteLine("Please try again");
                Console.WriteLine("");
                count_user = +1;
            }

            else
            {
                Console.WriteLine("Your username matches!");
                Console.WriteLine("");
                break;
            }

        } while (user_login != username && count_user < 3) ;
5
  • suppose to be a do loop, got cut at top do { } Commented Dec 1, 2015 at 4:12
  • 3
    count_user = +1; should be count_user += 1;. Please use a local debugger rather than Stack Overflow. Commented Dec 1, 2015 at 4:14
  • 1
    or even count_user++ Commented Dec 1, 2015 at 4:17
  • Sorry about that, but thank you so much! Commented Dec 1, 2015 at 4:24
  • Where are you initializing username ? Commented Dec 1, 2015 at 4:25

1 Answer 1

1

The way to get it to work is as @Ken Y-N said just change the count_user = +1 to count_user +=1; What is wrong with the first code is that every time instead of incrementing the variable count_user you are just constantly setting it to +1or basically positive 1. That is why it never leaves the loop.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.