using do-while loop

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.
tnx. such stupid of me not to realize..:)
Happens to all of us! :P
yah, its true... :p tnx again..
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)
Odd. The break instruction should cause the do while loop to exit immediately. Does the maximum number of tries message print?
nope, it strikes me odd also. should i use goto function to make thing easier?
i think the compiler breaks the do-while loop only. and not the whole system..
Hey put getchar(); before return 0; in your program. That will hold your program and you will be able to see message you want to see.
i'm using dev c++ compiler and the line system("pause"); just works the same.
It's working correctly on my PC.
Topic archived. No new replies allowed.