Sort and Search - Lotto

I need some help getting this to work please?

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
  #include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;

int main ()
{
	
int row, col, array [10] [6], lottonums [6];

cout << "Here is the numbers you have purchased.\n" << endl;

ifstream infile;

infile.open ("Array Data.txt");

cout << setprecision(2) << fixed << right;

	for(row = 0; row < 10; row++)
		{
		cout << "Group" << setw(3) << row+1;
     	for(col = 0; col < 6; col++ )
			{
	   	     infile >> array [row][col];
			cout << setw(8) << array [row][col] << " ";
			}
		cout << '\n';
		}
	
system("PAUSE");

cout << "\nWhat Are Today's Winning Numbers?\n";

	for (int i =0; i < 6; i++)
	{
		cout << "Enter Numbers One At A Time:";
		cin >> lottonums[i];
	}

	for (row = 0, row > 10, row++)
		for (col = 0, col > 6, col++)
			{
				if lottonums [col]!=
						array [row][col]
							break;
				if col = 6 got match
			}
		
infile.close();



return 0;
}
1
2
3
4
if lottonums [col]!=
						array [row][col]
							break;
				if col = 6 got match


brackets around these if conditions would be a good start, although
if col = 6 got match
isn't even legal code. plus if you're testing against a number, use '==' and not '='.
Last edited on
Ok I fixed it now thanks! But, it still doesn't do what it is suppose to?

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
#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;

int main ()
{
	
int row, col, array [10] [6], lottonums [6];

cout << "Here is the numbers you have purchased.\n" << endl;

ifstream infile;

infile.open ("Array Data.txt");

cout << setprecision(2) << fixed << right;

	for(row = 0; row < 10; row++)
		{
		cout << "Group" << setw(3) << row+1;
     	for(col = 0; col < 6; col++ )
			{
	   	     infile >> array [row][col];
			cout << setw(8) << array [row][col] << " ";
			}
		cout << '\n';
		}
	
system("PAUSE");

cout << "\nWhat Are Today's Winning Numbers?\n";

	for (int i =0; i < 6; i++)
	{
		cout << "Enter Numbers One At A Time:";
		cin >> lottonums [i];
	}

	for (row = 0; row > 10; row++ )
		{
			for (col = 0; col > 6; col++ )
				{
					if (lottonums [col] !=
					   array [row][col])
					   		break;
			   		if (col == 6)
			   		   cout << "You Have A Match!";
				}
		}
		
infile.close();



return 0;
}



This Is What Happens When I Run It, With A Number That Is In The File.

Here is the numbers you have purchased.

Group  1       8       15       28       29       48       59
Group  2      10       16       33       42       44       51
Group  3       5        7        8       14       21       29
Group  4      10       32       34       42       47       54
Group  5      11       21       27       28       37       38
Group  6       1       12       23       34       45       54
Group  7       7       11       22       33       44       50
Group  8       8       17       29       35       43       45
Group  9       1        3        5        7        9       11
Group 10       2        4        6        8       10       12
Press any key to continue . . .

What Are Today's Winning Numbers?
Enter Numbers One At A Time:2
Enter Numbers One At A Time:4
Enter Numbers One At A Time:6
Enter Numbers One At A Time:8
Enter Numbers One At A Time:10
Enter Numbers One At A Time:12

--------------------------------
Process exited with return value 0
Press any key to continue . . .
Your criteria for a match appears to be:
(col == 6)

Seems wrong to me? You need to compare your arrays (results and user input from file).
Ok how would I compare two arrays line by line?


1
2
3
4
5
6
7
8
9
10
11

bool same(true);
for(int i=0;i< (whatever your array size is); i++) 
{
     if(array1[i] != array2[i])
     {
         same = false;
         break;
      }
}

if 'same' is true then they're the same.
sort both arrays first in ascending or descending order. google 'bubblesort' for that.
Last edited on
Topic archived. No new replies allowed.