0

Okay i am trying to make a lock
this is my code:

#include <iostream>
using namespace std;

int main ()
{
    char key [10]="abcd";
    char answer[10];
    cout<< "password:";
    cin >> answer;
    if( key == answer)
    cout << "correct";
    else
    cout << "incorrect";
    return main();
}

when ever i try to run it, it keeps saying incorrect for everything, even when i type in the correct password.

3
Contributors
4
Replies
5
Views
10 Years
Discussion Span
Last Post by toko
0

Use a std::string to store both strings, if you want to compare them with ==

Otherwise, use strcmp() declared in #include <cstring>

0

oh sorry i am new to daniweb didn't know i had to

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.