The line "getline(cin,get_password);" doesn't repeat if the user chooses to re-enter the password. It pauses for a short while when it should run that line, refuses to accept any data, and then continues as normal.

#include<iostream>
#include<string>
#include<windows.h>
using namespace std;

int main()
{
    string get_password;
    string password="abc4";
    char repeat1;
    char repeat;
    do
    {

        cout<<"Please enter the password"<<endl;//The password is abc4
        getline(cin,get_password);
        do
        {
            cout<<"Password length check...";
            Sleep(1000);
            if(get_password.length()==password.length())
            {
                cout<<"Completed"<<endl;
                Sleep(500);
            }
            else
            {
                cout<<"Incorrect password"<<endl;
            }
        }
         while(repeat1=='Y'||repeat1=='y');

        if(get_password==password)
        {
            cout<<"The password is correct."<<endl;
            repeat='n';
        }
        else
        {
            cout<<"The password is incorrect."<<endl;
            cout<<"Do you want to re-enter the password?\tY/N"<<endl;
            cin>>repeat;

        }
    }
    while(repeat=='Y'||repeat=='y');
    return 0;



}

Yea the problem is that when the user enters 'y' or 'Y', he is actually entering that plus a newline character. The getline reads the newline character as a valid input, thus it gives you no opportunity to input a second time. One solution is to use cin.ignore() before the getline so that it ignores the newline character.

Also, one of your do-while s is testing repeat1, but the variable is never set nor read. It contains garbage.

I noticed it, but just wanted to clean up after I got the problem out of the way. It's out now

This article has been dead for over six months. Start a new discussion instead.