how to check if the user input is in the array list

*this is just a chunk of the code. the others arent that important
what the program is supposed to do:
- asks the user for a title.
- searches the array if its in it or not

i already declared all the index, title, etc. as global variables.

the text in the file is like this:
1 < -- index \
abc < -- title \
def < -- author \
hi hi <-- descrip 500 times
125 <-- isbn /
13 <-- copies /
2 <-- checked /
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
  ifstream file;
	file.open("Final.txt");  //opens the file
	string userTitle;
	
	while (file.good())
	{
		for (int x = 0; x < 500; x++)  //idk about this part lol. hope 
		{                                    //its right
			file >> index[x];
			file >> title[x];
			file >> author[x];
			file >> description[x];
			file >> ISBN[x];
			file >> copies[x];
			file >> checked[x];
		}
	}
	cout << "Please enter a title: " << endl; //asks the user for a title
	cin >> userTitle;
	cin.get();

// need help ovaah hurr. S.O.S D: 
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
// ...
cout << "Please enter a title: " << endl;
cin >> userTitle;
cin.get(); // not sure why you need this line

for (int x = 0; x < 500; x++)
{
	if(userTitle == title[x])
	{
		
	}
}


Side note: Next time when you ask a question, please explain what you're having trouble with in more detail. Be as verbose as possible.
Last edited on
oh woops sorry. was panicking too much forgot to be a little more specific :d

what i was asking for was: the user's supposedly enters something thats already in the array. how do i check if its in the array or not?

1
2
3
4
5
6
7
8
9
10
11
12
	cout << "Please enter a title: " << endl;
	cin >> userTitle;

	cout << title;
	cin.get();
	for (int x = 0; x < 500; x++)
	{
		if (userTitle == title[x])
		{
			cout << "hi";
		}
	}


so i was testing it and this is what i got

http://i62.tinypic.com/35lzpl3.png

uh.. guess this forum doesnt allow pictures..

1
2
3
4
5
6
7
8
9
10
11
cout << "Please enter a title: " << endl;
	cin >> userTitle;

	cin.get();
	for (int x = 0; x < 500; x++)
	{
		if (userTitle == title[x])
		{
			cout << title[x];
		}
	}


and then when i do this, nothing happens
Last edited on
Make sure that the code that reads from the file works.
Topic archived. No new replies allowed.