Question

I don't know what is causing this, but i think it has something to do with the function "password_checker" ??

here is my code :

#include <iostream>
#include <Windows.h>
#include <string>

using namespace std;

string password_checker();

int main()
{
string password;
cout << "please enter your password: " << endl;
cin >> password;
if (password == password_checker)
{
    cout << "Access granted" << endl;
}
else if (password == password_checker)
{
    cout << "Access denied" << endl;
}
Sleep(15000);
return 0;
}   

string password_checker()
{
string password = "123456";
return password;
}
Was it helpful?

Solution

password == password_checker

That's trying to call operator== on a string and a function pointer. You need to call the function so you get a string:

password == password_checker()

OTHER TIPS

You should call the function: password_checker().

And in else if part it should be not equals, !=, or just else.

Compiler thinks, that in line if (password == password_checker) you are trying to see if password variable and password_checker function are the same. You have to call that function: password_checker().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top