comparing user input with textfile and for loop

Hi. I am trying to compare what user enter with the data in my textfile. However, I am still not able to do any comparison. And on top of that, they will have only 3 tries to enter the input needed. once they exceed, the program will just end. Pls help me check. Thank you in advanced.

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
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
void Member();
using namespace std;

int main()
{
	int option;
	string member;
	cout<<"Welcome !\n";
	cout<<"1. Member"<<endl;
	cout<<"2. Non member"<<endl;
	cout<<"Please enter your option."<<endl;
	cin>>option;
	system("cls");
	{
	if (option==1)
	{
		Member();
	}
	else if (option==2)
	{
	Nmember();
	}
	else
		cout<<"Invalid choice!";
	}
	system("pause");
	return 0;
}
void Member()
{
	int i=0;
string line,userName,userNationality,airline,userType,type,userBirthday,birthday,userContact,Tmiles,userBenefit; 
ifstream inFile;
inFile.open("list.txt");
if (!inFile)
cout << "Unable to open file"<<endl;
else
		{
cout << "Enter birthday: ";
cin>>birthday;
while (!inFile.eof())
{
	inFile >> userName >> userNationality >> userContact >> userBirthday >> airline >> Tmiles >> userType >> userBenefit;
if (inFile.fail())
	break;
else
	for(i=0; i < 3; i++)
	{
	if (birthday == userBirthday)
	{
		system("cls");
		cout<<"welcome"<< " " << userName <<"!" << endl;
	}
	else
		cout<<"Invalid data ! ";
	}	
}
		}
}
Last edited on
First, put a breakpoint on line 48 and look at the values read in from the file.
erm. there is an error when i put the breakpoint there.
I have commented out line 25 (seeing as you haven't supplied code for that), put a breakpoint on line 48, added a blank file called "list.txt" in my project folder and run the code..
I CAN get to line 48.

I assume you do have implementation for Nmember()?? If not, delete line 25.
After I put breakpoint, it just stop after the birthday is entered. It did not check.
it's meant to stop, that's why it's called a breakpoint.
When it does stop, you can flip back to your code and see the values of the variables at that point in time in the code.
Topic archived. No new replies allowed.