When I input the username and password for user1, the first if-statement captures it however the error handling (else{}) still outputs even though it's already captured by the first if-statement.
Sample output:
Enter username: username1
Enter password: password1
Welcome User1!
Invalid username or password
Code:
Sample output:
Enter username: username1
Enter password: password1
Welcome User1!
Invalid username or password
Code:
#include<stdio.h>
#include<conio.h>
main(){
char user[80];
char pw[80];
char user1[] = "username1";
char pw1[] = "password1";
char user2[] = "username2";
char pw2[] = "password2";
char user3[] = "username3";
char pw3[] = "password3";
char user4[] = "username4";
char pw4[] = "password4";
char user5[] = "username5";
char pw5[] = "password5";
char user6[] = "username6";
char pw6[] = "password6";
char user7[] = "username7";
char pw7[] = "password7";
char user8[] = "username8";
char pw8[] = "password8";
char user9[] = "username9";
char pw9[] = "password9";
char user10[] = "username10";
char pw10[] = "password10";
printf("Enter username: ");
//scanf("%c",&let);
gets (user);
printf("Enter password: ");
//scanf("%d", &n);
gets (pw);
if((strcmp (user,user1) == 0)&&(strcmp (pw,pw1) == 0)){
printf("Welcome User 1!\n");
}
if((strcmp (user,user2) == 0)&&(strcmp (pw,pw2) == 0)){
printf("Welcome User 2!\n");
}
else{
printf("invalid username or passowrd");
}
getch();
}