Well, there are a few errors in your code. Have a look at the corrected code and see where you went wrong.
CODE
#include <iostream>
#include <string.h>
using namespace std;
int main() {
char user[]="USER"; char pass[]="PASS";
char username[50];
char password[50];
cout<<"Welcome to the simple login scheme, please enter username and password";
cin>>username;
cin>>password;
if (strcmp(user,username)==0 && strcmp(pass,password)==0)
{
cout<<"Successful Log-in";
}
else {
cout<<"Please try again";
}
}
First of all, you must choose the CORRECT username and password combination so that the user entry can be tested with the original.
Secondly, Since you are using character arrays to store strings, they must be compared character by character. So you will need to use the strcmp() function.
Since you are using the standard header files, you can also use this alternative:
CODE
#include <iostream>
#include <string>
using namespace std;
int main() {
string user="USER",pass="PASS";
string username;
string password;
cout<<"Welcome to the simple login scheme, please enter username and password";
cin>>username;
cin>>password;
if (user==username && pass==password)
{
cout<<"Successful Log-in";
}
else {
cout<<"Please try again";
}
}
This way you can compare the strings using the == and != operators and is easier to write and read, and is portable as well.
EDIT : Dang It...Amadeus was faster