int main ()
{
int i=3;
Char x= ' o ';
Char ch;
Tt:ch=getchar ();
GetChar ();
while (i)
{
if (' O ' ==ch)
{
printf ("Login successful \ n");
Break
}
else if (i>0)
{
i--;
printf ("Password error still has%d chance \ n", i);
if (i==0)
{
goto die;
}
goto tt;
}
die:printf ("Zhang brother Daniel \ \");
}
return 0;
}
This is a simulated user logon scenario and can only be logged on three times.
Only three password is allowed, if the password is correct, prompt to log in, if three times the input error, then quit the program.
Key issues:
<1> First say Goto statement, today for the first time use (particularly useful), usage: Must have a logo, the red and blue part of the above, that is the format. It is not advocated at this time because the program is too long and the error will affect the program running logic.
There are big problems, but as far as I can learn the small programs, the two words-too easy to use.
<2> I give the yellow part, need two, because in the black window every time the input needs to enter to determine, enter is also a character (' \ n '), if only write once, Gechar the second time to get the character must be ' \ n ', the program will be a big error, Because every time the input character will put it in a high-speed buffer area, every time GetChar () it will be in the buffer area to read, and after empty, it may be necessary for you to enter.
Practice Small topics (Assignment 6-18)