The == operator doesn't work this way on arrays. It sees the arrays as pointers as compares the pointers (if you haven't learned about pointers yet, suffice it to say that it's comparing the locations of the arrays in memory, rather than what the arrays contain). Also, don't forget to NUL-terminate your second array. I'm not sure that
does that for you, and you can't assume that the 5th byte in the array will be set to zero unless you make the array static. You have to set it manually. Here is my suggestion for corrections. I've highlighted lines I've changed or added.
using namespace std;
myArray = 0;
cout<< "Enter your Pin Number: " << "\n";
cin >> myArray;
if (std::strcmp(myArray, myPWD) == 0)
cout<< "Thats The Pin Number! Good Job!" << "\n";
cout<< myArray << " is the bad Pin Number..." << "\n";
You might notice that I changed string.h and stdio.h to cstring and cstdio respectively; standard headers in C++ don't end with a .h and headers from C also begin with a c. I also took out
and replaced it with
which waits for a keypress from the user. Please read http://www.cplusplus.com/forum/articles/11153/
for an explanation of why you shouldn't use the system function. Lastly I added
because, while the standard doesn't require it in the main function (the compiler will insert it automatically if you forget), it's best practice to always return a value (or throw one, but you'll learn about that when you study exceptions) at the end of a non-void function.