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...

What are you expecting it to do?

Debug your code.

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.