Feb 1, 2010 at 12:53am UTC
Hey, I'm working on a program which will allow the user to log in...
If the user types in the correct password, he will be logged in; If it's a wrong password, it will not let him log in...
******************************************************************
#include<iostream>
using namespace std;
int main()
{
char answer[10];
cout<<"Please enter the password: ";
cin>>answer;
cin.ignore();
if (answer[10] == 'wrox') {
cout<<"You have successfully logged in";
}
else {
cout<<"Wrong Password";
}
cin.get();
}
*********************************************************************
The problem is that when I run the program, and type in the password "wrox", it answers "Wrong Password" while it should say "You have successfully..."
Can anyone help? Please use simple language I'm just a beginner...
Last edited on Feb 1, 2010 at 2:30am UTC
Feb 1, 2010 at 12:56am UTC
I was actually just learning how to do stuff like this properly today. Based on what I have learned today..try the following:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include<iostream>
using namespace std;
int main()
{
string answer;
cout<<"Please enter the password: " ;
cin>>answer;
cin.ignore();
if (answer == 'wrox' ) {
cout<<"You have successfully logged in" ;
}
else {
cout<<"Wrong Password" ;
}
cin.get();
}
That will work.
Also I have gotten in the habit of doing std::whatever with using the namespace incase I am ever having to use multiple namespaces...
Last edited on Feb 1, 2010 at 12:57am UTC
Feb 1, 2010 at 2:32am UTC
Thanks for the reply but it didn't work :(
It says "no match for 'operator==' in 'answer==2003988344"
Feb 1, 2010 at 2:38am UTC
use double qoute
if (answer=="wrox" )