[ back to toc ]

Looping problem

Date: 2002/04/08 12:11

Hi, I am new in C programming, i currently using borland C++ compiler.
the question is:
Before the program will display the menu, the user will be asked to enter
in their userid and password, thus:
Enter Your Userid: Penny
Enter Your Password: klingon
It does not matter what the userid is but the password must be ‘klingon'.
The user has 5 changes to get the password right. If they do not the
program will exit, if they do, the menu will display.

I am not able to get the counter to work, for the programe to stop after 5
wrong entries. Please advice.
To have a counter that counts the wrong trials you need an 'int' type of
variable. It has to be initialized, incremented at each wrong guess and
exit the program if the counter goes too high. For example (program

int counter;

counter = 0;

get the password here
if( password is correct )break;
counter ++;
if( counter > 5 )exit(1);


[ back to toc ]