Why my do-while loop is not doing as I wanted?

I had an idea to make a program that will ask your password again if u type the
following password,for example:password,abc123,qwerty.

I try to apply a do-while loop, but when I input my password as "abc123", it doesnt ask again the user to reinput his password. Can someone help me?

here is the code:

#include "stdafx.h"
#include <stdio.h>
#include <iostream>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
cout<<"Please enter your password,"<<endl<<"Your password should not be 'password','abc123' or 'qwertz'"<<endl;
char first[]="password";
char second[]="abc123";
char third[]="qwertz";
char x[100];
do
{
cin>>x;
}
while((x==first) || (x==second) || (x==third));

return 0;
}
Why are you avoiding std::string?

Your issue is that you are comparing the memory addresses of the character arrays instead of the contents of the character arrays. It is highly recommended not to use character arrays, and this is a good example why.

Also, what if the user enters a password that is more than 99 characters? What if they want spaces in their password?
Last edited on
Topic archived. No new replies allowed.