samedi 22 mai 2021

problem in c++ if statement the first if is working but the second isnt anyone know why?

I have a problem in the last if the function is not working properly the program is ending before asking for password? ............................................. ................................................................................... the second function is not working the code is ending before asking for password idk y anyone help?

struct Client {
    int id;
    string prenom;
    string nom;
    string password;
    string email;
    string number;
};

void addperson( fstream &f, Client person ) {

    f << "\n" << person.id << "\t" << person.prenom << "\t" << person.nom << "\t" << person.password <<
        "\t" << person.email << "\t" << person.number;

}

void findperson( fstream &f, Client person1 ) {
    Client person;
    while ( f ) {
        f >> person.id;
        f.ignore( INT_MAX, '\t' );
        getline( f, person.prenom, '\t' );
        getline( f, person.nom, '\t' );
        getline( f, person.password, '\t' );
        getline( f, person.email, '\t' );
        getline( f, person.number );
        if ( person1.email == person.email && person1.password == person.password ) {
            cout << "id:" << person.id << " prenom: " << person.prenom << " nom: " << person.nom << endl;
        }
    }
}

int main()      {
    fstream file( "clients.txt", ios::in | ios::out | ios::app );
    int a = 0;
    cout << "press 1 for new or 2 for old user" << endl;
    cin >> a;
    while ( a != 1 && a != 2 ) {
        cout << "press 1 for new or 2 for old user" << endl;
        cin >> a;
    }
    if ( a == 1 ) {
        Client person1;
        cout << "entrer votre id,prenom,nom,password,email,number" << endl;
        cin >> person1.id;
        cin.ignore( INT_MAX, '\n' );
        getline( cin, person1.prenom );
        getline( cin, person1.nom );
        getline( cin, person1.password );
        getline( cin, person1.email );
        getline( cin, person1.number );
        addperson( file, person1 );
    }   else if ( a == 2 ) {
        Client person2;
        cout << "give mail and password" << endl;
        getline( cin, person2.email );
        getline( cin, person2.password );
        findperson( file, person2 ); here help plz.................................... ? ? ?
    }
    file.close();
}

Aucun commentaire:

Enregistrer un commentaire