Hello World,
I was trying to make a program that takes a password from the user and tells if it true or false.
Note: Write the program without using arrays. Use getch(). 3 trials are permitted. The password is asueng.
Here's my code:
Code:
#include <stdio.h>
int main(void)
{
int count = 0, trial = 0;
char letter;
while ( trial++ < 3 )
{
printf("Enter the password (%d): ", trial);
while ( 1 )
{
letter = getch();
if ( letter == "\n" && count == 6 )
{
printf("Accepted\n");
return 1;
}
else if ( letter == "\n" && count != 6 )
{
printf("Not Accepted..\n");
break;
}
else
{
printf("*");
if ( (letter == 'a' && count == 0) ||
( letter == 's' && count == 1 ) ||
( letter == 'u' && count == 2 ) ||
( letter == 'e' && count == 3 ) ||
( letter == 'n' && count == 4 ) ||
( letter == 'g' && count == 5 )
)
count += 1;
else
{
if ( count > 0 )
count -= 1;
else
count = 0;
}
}
}
}
return 0;
}
The problem I'm facing is when I press Enter it prints a * which something I don't want. It should execute the code in if or the first else if. What's going wrong?
Thanks in advance.