Reputation: 1
This is a program in which someone inputs a password and gets three tries to
guess the password. When I compile it, I get multiple errors, one of which includes line 13, where it basically says that it cannot find a similar function included in the Password_Program
class.
#include <iostream>
using namespace std;
class Password_Program
{
private:
string password;
public:
Password_Program();
void login();
string passAttempt;
};
Password_Program::Password_Program()
{
cin >> password;
}
Password_Program::login()
{
for (int i = 0; i < 3; i++)
{
cin >> passAttempt;
if (passAttempt == password)
{
cout << "Success!" << endl;
break;
}
else if (i >= 3) { cout << "Try again later" << endl;
break; }
else { cout << "Sorry, try again" << endl; }
}
}
int main() {
Password_Program myPassword;
myPassword.login;
return 0;
}
Upvotes: 0
Views: 90
Reputation: 276
2 things are there
Here is the right code.
#include <iostream>
using namespace std;
class Password_Program
{
private:
string password;
public:
Password_Program();
void login();
string passAttempt;
};
Password_Program::Password_Program()
{
cin >> password;
}
void Password_Program::login()
{
for (int i = 0; i < 3; i++)
{
cin >> passAttempt;
if (passAttempt == password)
{
cout << "Success!" << endl;
break;
}
else if (i >= 3) { cout << "Try again later" << endl;
break; }
else { cout << "Sorry, try again" << endl; }
}
}
int main() {
Password_Program myPassword;
myPassword.login();
return 0;
}
Upvotes: 0
Reputation: 206567
You forgot the return type in the definition of Password_Program::login()
.
Change
Password_Program::login() {....}
to
void Password_Program::login() {....}
Upvotes: 2
Reputation: 1736
Your definition of the login()
method is missing a return type. It should be:
void Password_Program::login()
{
...
}
You've also forgotten brackets when calling it:
myPassword.login();
Upvotes: 5