As this is C++, why don't you use C++?
Also, never use gets().
The reason you are failing is that charname will never == chartryname, since both are pointers and both point to different locations. If you use the std::string class, the == operators are overloaded so that you can use == the way you think it ought to be working...
#include <iostream>
#include <string>
#include <cstdlib> // for system(), alas.
using namespace std;
int main()
{
string name, password, tryname, trypassword;
int numtrys;
cout << "Please enter a user name to setup ";
getline( cin, name );
cout << "Pleae enter a password to setup ";
getline( cin, password );
system( "cls" ); // there are better ways to do this...
for (numtrys = 0; numtrys < 3; numtrys++)
{
cout<<"You have 3 attempts"<<endl;
cout<<"This is attempt number "<<numtrys<<endl;
cout<<"Please enter your user name ";
getline( tryname );
cout << "Please enter your password ";
getline( trypassword );
if ((tryname == name) and (trypassword == password))
{
cout<<"\t The details you entered are correct "<<endl;
break;
}
else
cout<<"\t The details you entered are incorrect "<<endl;
}
if (numtrys < 3) cout << "yeah!" << endl;
cout << "Press ENTER to continue...";
cin.ignore( numeric_limits<streamsize>::max(), '\n' );
return EXIT_SUCCESS;
}
Hope this helps.