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

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

Recommended Answers

What are you expecting it to do?

Jump to Post

All 3 Replies

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 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.