float dc[5]={3,3.25,3.5,4.6,6.6};
float df[3]={30,40,50};
float cf=120;
void getslab()
{
char ch;int count=0;
char user[8],pass[8];
strcpy(user,"Admin@00");
strcpy(pass,"Access00");
cout<<"\nDo you wish to change the Consumption rates ?(Y/N) : ";
cin>>ch;
if((ch=='Y')||(ch=='y'))
{
cout"\nWarning ! , This will change all the bill rates !\n\tThis cannot be undone ,";
cout<<"\nAnd You must take Full responsibility if the System crashes !";
cout<<"\nDo you really want to change the rates ?(Y/N) : ";
cin>>ch;
if((ch=='Y')||(ch=='y'))
{
if(count>=3)
{
cout<<"\nTrials Exceeded !!!";
cout<<"\nExitting Program !!!";
exit(1);
}
again:
clrscr();
cout<<"\nAdmin Login";
cout<<"\n----- -----\n\n";
cout<<"\nAdmin Name : ";
cin>>user;
cout<<"\nPassphrase : ";
cin>>pass;
if((strcmp(user,"Admin@00"))&&(strcmp(pass,"Access00")))
{
//change rates
}
else
{
cout<<"\nTry Again !!!";
count++;
goto again;
}
}
else
{
cout<<"\nThe Rates are as Before !";
}
}
else
{
cout<<"\nThe Rates are as Before !";
}
}
You need to take another look at the documentation for strcmp, to see what the return value actually means. What you've written right now won't do what you want it to do.
As you would have known, if you'd taken two minutes to run and test it.
float dc[5]={3,3.25,3.5,4.6,6.6};
float df[3]={30,40,50};
float cf=120;
void getslab()
{
char ch;int count=0;
char user[8],pass[8];
strcpy(user,"Admin@00");
strcpy(pass,"Access00");
cout<<"\nDo you wish to change the Consumption rates ?(Y/N) : ";
cin>>ch;
if((ch=='Y')||(ch=='y'))
{
cout"\nWarning ! , This will change all the bill rates !\n\tThis cannot be undone ,";
cout<<"\nAnd You must take Full responsibility if the System crashes !";
cout<<"\nDo you really want to change the rates ?(Y/N) : ";
cin>>ch;
if((ch=='Y')||(ch=='y'))
{
again:
if(count>=3)
{
cout<<"\nTrials Exceeded !!!";
cout<<"\nExitting Program !!!";
exit(1);
}
clrscr();
cout<<"\nAdmin Login";
cout<<"\n----- -----\n\n";
cout<<"\nAdmin Name : ";
cin>>user;
cout<<"\nPassphrase : ";
cin>>pass;
if((strcmp(user,"Admin@00/0")==0)&&(strcmp(pass,"Access00/0")==0))
{
//change rates
}
else
{
cout<<"\nTry Again !!!";
count++;
goto again;
}
}
else
{
cout<<"\nThe Rates are as Before !";
}
}
else
{
cout<<"\nThe Rates are as Before !";
}
}
It seems that you misunderstood.
`user' has to have enough space to hold each character of the "Admin@00" string and the null terminator. {'A', 'd', 'm', 'i', 'n', '@', '0', '0', '\0'}
right now you have char user[8], so it may only store seven characters and the null terminator, but you need to store eight characters.
It seems that you misunderstood.
`user' has to have enough space to hold each character of the "Admin@00" string and the null terminator.
{'A', 'd', 'm', 'i', 'n', '@', '0', '0', '\0'}
right now you have char user[8], so it may only store seven characters and the null terminator, but you need to store eight characters.