Hi,
I'm new at C++
I need help with my code.
I want to be able to output a message when all attempts have been used up, however my program just ends when attempts reach 0.
I know its a super easy fix, I just can't find out what it is.
Thankyou!
Code:
int main()
{
string correctPassword = "OpenSesame";
string password;
for (int attempts = 4; attempts > 0; attempts--)
{
cout << "Please enter your password: ";
cin >> password;
if(password == correctPassword)
{
cout << "CORRECT PASSWORD ENTERED!\n\n" << "Please wait . . . \n\n\n";
break;
}
else if(attempts == 0)
{
cout << "WARNING: All attempts failed! System shutting down . . .\n\n";
}
else
{
cout << "INCORRECT PASSWORD ENTERED!\n\n";
cout << "Attempts left: " << attempts - 1 << "\n\n";
}
}
return 0;
}