Hey I know i am over looking somthing small but can i get some help on line 23

(strcmp(chartryname, charname)==0 && (chartrypassword, charpassword) ==0){

I know this will not work its just to show what i am trying to do. I need to check two pairs of strings how should I write the and part of the if statment.
any help would be great thanks.

//login with loop
#include <iostream.h>
#include <stdlib.h>
#include <stdio.h>  // for gets
#include <string.h> // for string

int main()
{

char charname[10],charpassword[15],chartryname[10],chartrypassword[15];
            cout<<"Please enter a user name to setup\n ";
            gets(charname);

            cout<<"Please enter a password to setup\n ";
            gets(charpassword);
  
            cout<<"Please enter your user name\n ";
            gets (chartryname);
            cout<<"Please enter your password\n ";
            gets (chartrypassword);

if
   (strcmp(chartryname, charname)==0 && (chartrypassword, charpassword) ==0){
            cout<<"\t The details you entered are correct "<<endl;
}
 else
{
         cout<<"\t The details you entered are incorrect "<<endl;
}

   //end of if statment
 //end of loop


          system("PAUSE");
          return 0;

} //end main

>>strcmp(chartryname, charname)==0 && (chartrypassword, charpassword) ==0

Like this: if( (strcmp(chartryname, charname)==0) && (strcmp(chartrypassword, charpassword) ==0) ){

Thanks Ancient Dragon I corrected the lin but still have the same problem. If I input the correct user name and password I get told the details are incorrect. When I test it with just one variable either name or password it works fine. I just cant get it working with 2 at once. Any ideas?

>>Any ideas?

Yes -- post code.

I did post the code in the original message but here it is again

//login with loop
#include <iostream.h>
#include <stdlib.h>
#include <stdio.h>  // for gets
#include <string.h> // for string

int main()
{

char charname[10],charpassword[15],chartryname[10],chartrypassword[15];
            cout<<"Please enter a user name to setup\n ";
            gets(charname);

            cout<<"Please enter a password to setup\n ";
            gets(charpassword);
  
            cout<<"Please enter your user name\n ";
            gets (chartryname);
            cout<<"Please enter your password\n ";
            gets (chartrypassword);

if
   (strcmp(chartryname, charname)==0 && (chartrypassword, charpassword) ==0){
            cout<<"\t The details you entered are correct "<<endl;
}
 else
{
         cout<<"\t The details you entered are incorrect "<<endl;
}

   //end of if statment
 //end of loop


          system("PAUSE");
          return 0;

} //end main

you are mixing C and C++ -- not good for your grades. for input gets() is NEVER EVER recommended even in C programs because it can screw up your program. In c++ use either cin or getline.

cout<<"Please enter a user name to setup\n ";
cin.getline(charname, sizeof(charname));

You still did not fix that if statement like I showed you (which is why I wanted you to repost your code). Go back and re-read my previous post paying very careful attention to the correction I made to that line.

Sorry about that this is the modified code with cin>> instead of gets

//login with loop
#include <iostream.h>
#include <stdlib.h>
#include <stdio.h>  // for gets
#include <string.h> // for string

int main()
{

char charname[10],charpassword[15],chartryname[10],chartrypassword[15];
            cout<<"Please enter a user name to setup\n ";
            cin>> charname;

            cout<<"Please enter a password to setup\n ";
            cin>> charpassword;
  



            cout<<"Please enter your user name\n ";
            cin>> chartryname;
            cout<<"Please enter your password\n ";
            cin>> chartrypassword;

if
   ((strcmp(chartryname, charname)==0 && (chartrypassword, charpassword) ==0)){
            cout<<"\t The details you entered are correct "<<endl;
}
 else
{
         cout<<"\t The details you entered are incorrect "<<endl;
}

   //end of if statment
 //end of loop


          system("PAUSE");
          return 0;

} //end main

hey just noticed the differance in your if statment to mine now it works perfectly. its 01:20 here and im a bit tired thanks a million Ancient Dragon:)

[edit]nevermind. You already fixed it.[/edit]

One possible solution to your if block is:

if( !(strcmp(chartryname,charname)) && !(strcmp(chartrypassword,charpassword) )
cout<<"All entries are correct";

/*
Result at execution if entries are correct :

if( !(0) && !(0) ) => if ( 1 && 1) => true

*/

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.