Matching the value from input and value from a text file

Hello. I have a text file consisting of member data. I am developing a program where we can use the account number to match the account number in the program to get the correct member data. But I dont know why, the program is not working, I cant match the value. Can anyone help me identify what is the error.

Content of Membership.txt
1
2
3
Mathavan|021127100897|MathavanKrishnan27@gmail.com|0167750575|1410065449|Mathavan1234|3|2022
Mathavan|021127100897|MathavanKrishnan27@gmail.com|0167750575|1410065448|Mathavan1234|3|2024
Mathavan|021127100897|MathavanKrishnan27@gmail.com|0167750575|1410065447|Mathavan1234|3|2022


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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
  string member_login(){
    title();
    fstream member;
    member.open("Membership.txt",ios::in);
    string pass_input, line, acc_num1, password1;
    int login_attempt = 0, count = 0 , account = 0;
    char dummy, resp, accno_input[25], name[25], icno[25],email [40], phone_number[25],acc_num[25],password[25],month[25], year[25];

    account_num:
    cout << "                                          Enter your account number : ";
    cin >> accno_input;

    ifstream file("Membership.txt");
    while (!file.eof()){
        getline(file, line);
        count++;
     }

    cout << accno_input;
    int i = 0;
    while(i <= count)
    {
        member.getline(name,25,'|');
        member.getline(icno,25,'|');
        member.getline(email,40,'|');
        member.getline(phone_number,25, '|');
        member.getline(acc_num,25, '|');
        member.getline(password,25,'|' );
        member.getline(month,25,'|' );
        member.getline(year, 25);

        cout << name << " ";
        cout << icno << " ";
        cout << acc_num << " ";
        cout << accno_input;

        if (acc_num == accno_input){
            account = 1;
            break;
        }

        i ++;
    }

    cout << account;

    member.close();

    if ( account != 1 ){
        cout << endl;
        cout << "                                  Your account not found !!!"<< endl;
        cout << "                                  Please try again !!" << endl << endl;
        cout << "                                  PLEASE ENTER ANY KEY TO CONTINUE >>> ";
        cin >> dummy;
        goto account_num;
    }

    password1 = password;
    cout << endl;
    cout << "                                          Enter your account password : ";
    cin >> pass_input;

    for (login_attempt = 1 ; login_attempt <= 2 ; login_attempt ++){
        if (pass_input == password1){
            cout << "Login Successful !!!";
            break;
        }

        cout << endl;
        cout << "Login Failed. Attempt " << login_attempt  << " of 3" << endl;
        cout << "Please re-enter Password: " ;
        cin >> pass_input;

        if (pass_input == password1){
            cout << "Login Successful !!!";
                break;
        }
    }

    if ( login_attempt == 3){
        cout << endl;
        cout << "Login Failed. Attempt 3 of 3";
    }

    return accno_input;
}
using getline you may get a stray space or anything else. equality means exact match, not 'pretty close' and it also means exact in case, whitespace, etc.

you can debug to look at the two values to see what is different.
if you get desperate, print them in hex instead of text.
Last edited on
Topic archived. No new replies allowed.