I'm writing a program where you allow someone to login. but i can't make it print successfully login when the id and password i input is equal to the preset value.
int main()
{
int id,pass,idC=0,passC=0,i,myid,mypass,tries=1;
myid = 10082612;
password = 123456;
printf("**LOG IN**\n\n");
printf("ID: ");
scanf("%d", &id);
printf("Password: ");
scanf("%d", &pass);
while(id != 0){
id /= 10;
idC++;
}
while(pass!= 0){
pass /= 10;
passC++;
}
if(idC==8 && passC ==6 || idC==7 && passC==6){
if(id==myid && pass==mypass){
printf("Successfully Login");
}
else{
printf("Unknown ID");
}
}
else if(idC!=8 && passC==6 || idC!=7 && passC==6){
printf("The Student ID should be in 7 or 8 digits, please try again");
}
else if(idC==8 && passC!=6 || idC==7 && passC!=6){
printf("Please enter a 6-digit pin");
}
}
This is what I've wrote.
if(id==myid && pass==mypass)
and it all – Ivan Sheigets Oct 2 '17 at 12:29password
? The code you posted here doesn't compile. – Jabberwocky Oct 2 '17 at 12:30id
andpass
entered by user (id /= 10;
andpass /= 10;
). Their value will always be zero when while loop breaks, so thats why yourif(id==myid && pass==mypass)
condition is failing. To correct it, store it in different variable and proceed. – svtag Oct 2 '17 at 12:32password = 123456;
– ryyker Oct 2 '17 at 12:32pass
andid
will be 0 – Ivan Sheigets Oct 2 '17 at 12:32