0
void password(){
        string fpass;
    string pass;
    cout << "Type the password " << endl;
    getline(cin,pass);
    cin.ignore();
    ifstream fin(FILENAME1);
    string str;
    getline(fin, str);
    fpass = str;
    cin.ignore();
    if (pass.compare(fpass) == 0){
        cout << "    Hello!" << endl << endl;
        cout << "What do you want to do?" << endl;
    }else{
        cout << "\n\n INCORRECT! \n \n \n";
        cin.ignore();
        char choice;
        cout << "Try again? y/n -->   ";
        cin >> choice;
        if (choice == 'y'){
            password();
        }
    }
}

What's the problem with this? It worked, but didn't do what I expected...

Edited by deceptikon: Moved to C++

3
Contributors
3
Replies
21
Views
3 Years
Discussion Span
Last Post by LucasMNF55
1

Debug your code.

Output the value of pass and fpass at the start, and each time you think they should (or may) have changed.

0

Thanks, it's working now! When I typed the correct password, the program stopped. But the problem was the "fpass = str". I changed it to "fpass == str", and now it's working perfectly.

This topic has been dead for over six months. 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.