Тема: Як вийти з циклу for, якщо умова була зроблена
#include <iostream>
using namespace std;
void checkUser(char *userlogin, char *userpassword);
int main() {
char userlgn[30];
char userpwd[30];
checkUser(userlgn, userpwd);
return 0;
}
void checkUser(char *userlogin, char *userpassword) {
const char loginAdministrator[] = "Admin";
const char passwordAdministrator[] = "Admin";
cout << "Enter the login: ";
cin >> userlogin;
cout << "Enter the password: ";
cin >> userpassword;
int cmplogin = strcmp(userlogin, loginAdministrator);
int cmppassword = strcmp(userpassword, passwordAdministrator);
if (cmplogin == 0 && cmppassword == 0) {
cout << "You have been entered as administrator." << endl;
}
else {
for (int verify = 0; verify < 3; verify++) {
cout << "\nUncorrect login or password.\n\tAttempts to enter left " << 3 - verify << endl;
cout << "Enter the login: ";
cin >> userlogin;
cout << "Enter the password: ";
cin >> userpassword;
/*if (cmplogin == 0 && cmppassword == 0) {
cout << "You have been entered as administrator.";
//continue;break;
}*/
}
cout << "\n\nAccess denied!The number of attempts is limited!" << endl;
}
}