Hello arctic_blizzard!
To gain entrance to a secret area you often need a secret password consisting a sequence of alphanumeric characters that must be entered in a specified order. Create a program that reads in characters
until the user enters the correct two character sequence (cs) to open the door.
Did you see the main problem in the bold text?
You can get two character sequence by doing this:
Code:
char c1, c2;
c1 = getchar();
c2 = getchar();
So, check the characters inputted by user are correct or not:
Code:
if(c1 == 'a' && c2 == 'b')
{
printf("Correct password.");
}
else
{
printf("Incorrect password.");
}
And you can make your program request to the user repeatly:
Code:
for(;;)
{
//request to the user
}
At last, if we combine them, should be look like this:
Code:
for(;;)
{
char c1, c2;
printf("Please enter the password: ");
c1 = getchar();
c2 = getchar();
if(c1 == 'a' && c2 == 'b')
{
printf("Correct password.");
break; //Exit loop
}
else
{
printf("Inorrect password.");
}
}