Help with this program..I only get the true valu of the condition.

Dec 6, 2015 at 9:50am
I compared two strings but i only get the 'true' condition..help please..TIA!
[code]
#include <iostream>
#include<conio.h>
using namespace std;
main()
{
char name[30],pass[10],conpass[10];
int i=0,d=0;
cout<<"Enter Account Name: ";
cin>>name;
cout<<"Enter Password: ";
pass[0]=_getch();
while(pass[i] =13)
{
i++;
cout<<"*";
pass[i]=_getch();
}
cout<<"\nConfirm Password:";
conpass[0]=_getch();
while(conpass[d]!=13)
{
d++;
cout<<"*";
conpass[d]=_getch();
}
if (strcmp(pass,conpass)!=0)
{
cout<<"\nRegistration complete!";
}
else
{
cout<<"\nTry again!";
}
system ("pause>0");




}
Last edited on Dec 6, 2015 at 12:08pm
Dec 6, 2015 at 9:51am
i always get a true value if i use ==, while the strcmp doesnt work..
Dec 6, 2015 at 9:57am
while(pass[i] =13)
This makes no sense. What are you trying to do with this line of code?
Dec 6, 2015 at 10:20am
am sorry @Moschops that was supposed to be pass[i]!=13
Last edited on Dec 6, 2015 at 10:20am
Dec 6, 2015 at 10:51am
if (strcmp(pw,conpass)!=0)

I see you're trying to compare conpass and pw. This is unfortunate, as pw doesn't exist. You can only compare variables that exist.
Dec 6, 2015 at 11:01am
sorry my bad..i chaged it now..
it alway says
[Error]'strcmp' was not declared in this scope.
Dec 6, 2015 at 11:11am
You forgot to include the <cstring> header that defines this function. So the function isn't actually declared in your code and the compiler cannot find it.
Dec 6, 2015 at 11:23am
it worked but it only returns the 'true' value..
Dec 6, 2015 at 12:43pm
strcmp returns zero when the two strings are the same.
Topic archived. No new replies allowed.