Когда пользователь вводит неверный пароль, код должен перезагрузиться, когда они попытались в два раза прекратить код, но в моем коде, когда пользователь вводит неверную информацию и передает пароли_треты он продолжает идти все остальное, кажется, работает просто отличноБез использования цикла, как я могу выполнить итерацию кодовой инструкции
#include <iostream>
#include <string>
using namespace std;
int main()
{
string myusername;
string mypassword;
bool Access_granted;
int password_attempts;
cout << "Enter your username: ";
cin >> myusername;
cout << "Enter your password: ";
cin >> mypassword;
if (myusername == "veasy62" && mypassword == "a65908") {
Access_granted = true;
cout << "Access granted veasy62\n";
}
else if (myusername == "tveasy62" || mypassword == "a1065908") {
Access_granted = true;
cout << "Access granted tveasy62\n";
}
else {
Access_granted = false;
cout << password_attempts;
cout << "Access Denied, Sorry try again\n";
if (Access_granted == false) {
if (password_attempts = 2) {
password_attempts = password_attempts + 1;
return main();
}
else {
cout << "Sorry you have ran out of attempts\n";
}
}
}
}
Вы не можете называть главное, как обычную функцию. §3.6.1 –
Почему вы не можете использовать циклы? Разбиты ли ваши ключи f и w? –
Все остальное в стороне, вероятно, поможет, если вы использовали 'password_attempts == 2' вместо' password_attemps = 2'. – Dolda2000