Searching and Sorting Arrays

Heyy guys. I'm kinda new to c++ and I'm totally stuck :/ Nothing happens after I enter the ticket number. I don't know what's wrong with my code :( I need some help with this. Thanks :)

Question:
A lottery ticket buyer purchases 10 tickets a week, always playing the same 10 5-digit “lucky” combinations. Write a program that initializes an array or a vector with these numbers and then lets the player enter this week’s winning 5-digit number. The program should perform a linear search through the list of the player’s numbers and report whether or not one of the tickets is a winner this week. Here are the numbers:
13579 26791 26792 33445 55555
62483 77777 79422 85647 93121

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
  #include <iostream>
using namespace std;

int searchList (const int [], int, int);
const int SIZE =10;

int main ()

{
	int tickets [SIZE]= {
		13579, 26791, 26792, 33445, 55555,
		62483, 77777, 79422, 85647, 93121 };
	int winningNumber;
	int results;

	cout << "\nPlease enter this week's winning 5-digit number: ";
	cin >> winningNumber;

	results=searchList (tickets, SIZE, winningNumber);

	if (results==-1)
		cout << "None of your tickets is a winner.\n";
	else
		cout << "Your ticket is a winner this week." << endl;
	return 0;
}

int searchList (const int list[], int numElems, int value)
{
	int index=0;
	int position=-1;
	bool found=false;

	while (index < numElems && !found)
	{
		if (list[index]==value)
		{
			found=true;
			position=index;
		}
		index++;
	}
	system ("pause");
	return position;
}
i didn't have any problems with your code. to keep the window open after running, add another system("pause"); or cin.ignore(2); in between line 24 and 25.
This is one of my homework problems on Myprogramminglab and it doesn't accept my answer. It keeps saying there's a logical error :/
Topic archived. No new replies allowed.