help me...i'm beginner
why does it say "both ID and PASSWORD are WRONG " eventhough i write id=1,password=2....i thought it just need to say "id is correct"...help
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
#include<iostream>
#include<cstring>
using namespace std;
int main(){
bool a=true;
char id[]="1";
char id2[50];
char password[]="1";
char password2[50];
while(a)
{
cout<<"ID= ";cin>>id2;
cout<<"password= ";cin>>password2;
if(strcmp(id,id2)==0&&strcmp(password,password2)==0){cout<<"READY\n";a=false;}
if(strcmp(id,id2)==0&&strcmp(password,password2)!=0){cout<<"JUST ID is CORRECT \n";}
if(strcmp(id,id2)!=0&&strcmp(password,password2)==0){cout<<"JUST PASSWORD is CORRECT\n";}
else{cout<<"both ID and PASSWORD are WRONG\n";}
}
}.
|
Last edited on
1 2
|
if(strcmp(id,id2)!=0&&strcmp(password,password2)==0){cout<<"JUST PASSWORD is CORRECT\n";}
else{cout<<"both ID and PASSWORD are WRONG\n";}
|
The
if
condition here isn't true with that input (id good, password bad), so the code in the
else
executes.
I suspect you want the
if
statements on lines 23 and 24 to be
else if
.
i got it now...appreciate that....good man :)
Last edited on
Topic archived. No new replies allowed.