hello,
i am trying to develop a username-password program using do-while loop. here is my code:
do{
if (mainAtt1==0){
cout<<"You have reached maximum attempt of tries..."<<endl;
break;
}
system("cls");
system("color 5a");
cout<<"\n\n\n\t\t\tPassword attempt left:"<<mainAtt1-1<<endl;
cout<<"\n\n\t\t\t Enter Username:";
cin.getline(mainUN,20);
cout<<"\t\t\t Enter Password:";
cin.getline(mainPW,20);
mainAtt1=mainAtt1-1;
}
while((strcmp(mainUN,mainDbUN)!=0) && (strcmp(mainPW,mainDbPW)!=0));
my problem is, the loop will function properly if i entered a wrong username and wrong password. but when i entered a correct username but wrong password, the loop did not go back again..
change the && to || in the while check. The condition right now is that keep looping while username is incorrect AND password is incorrect. If one is correct then the loop exits.
got a question again, seems there is something wrong. when i reached the maximum attempt of tries, the loop does not break, but continues to access my main program. should i use goto function? or break? (on the if statement)