SaltyLegend
SaltyLegend

Reputation: 19

While Loop, Program Error

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) ;

Upvotes: 0

Views: 77

Answers (1)

Mindstormer
Mindstormer

Reputation: 294

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.

Upvotes: 1

Related Questions