wrong random numbers

I'm trying to make lotto program.
and when this program generate numbers in between 1 and 40.
they display -858993460 7 times
I don;t know what's wrong with my code

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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdlib>
#include <time.h>
using namespace std;


void genWinNum(int getNum[])
{
	const int MAX_NUM = 40;
	const int MIN_NUM = 1;
	const int NUM = 7;
	int num[NUM];

	srand(time(NULL));

	for(int i = 0; i < NUM; i++)
	{
		num[i] = (rand() % 40) + 1;// generate random number 1 to 40
		while(num[i] < 1 || num[i] > 40)// more than 40 and less than 1 is false
		{
			num[i] = (rand() % 10) + 1;// generate random number again till getting number between 1 to 40
		}
		if(i > 0)
		{
			for(int index = 0; index < i; index++)
			{
				while(num[i] == num[index])//generate number not to duplicate
				{
					num[i] = (rand() % 10) + 1;
				}
			}
		}
	}
	return;
}

void* getLottoPicks(int userTicket[])
{
	const int COUNT = 7;
	userTicket[COUNT];
	int* ticket = userTicket;
	for(int i = 0; i < COUNT; i++)
	{
		cout << "Enter your number " << i+1 << ": " << endl;
		cin >> userTicket[i];
		while(userTicket[i] < 1 || userTicket[i] > 40)
		{
			cout << "The number must be between 1 and 40. Please enter another number:" << endl;
			cin >> userTicket[i];
		}
		if(i > 0)
		{
			for(int index = 0; index < i; index++)
			{
				while(userTicket[i] == userTicket[index])
				{
					cout << "No duplicated numbers are accepted. Please enter another number:" << endl;
					cin >> userTicket[i];
				}
			}
		}
	}
	return ticket;
}
int main()
{
	string user;
	int playLotto;
	int num[7];
	int nums[7];
	int genNum[7];
	cout << "LITTLETON CITY LOTTO MODEL:\n---------------------------\n1) Play Lotto\nq) Quit Program\nPlease make a selection:" << endl;
	cin >> playLotto;

	while(playLotto == 1)
	{
		cout << "Enter your name:" << endl;
		cin >> user;
		
	    getLottoPicks(num);

		genWinNum(genNum);

		for(int i = 0; i < 7; i++)
		{

			cout << genNum[i] << endl;// show generated random numbers
			
		}
		for(int i = 0; i < 7; i++)
		{
		
			cout << num[i] << endl;// show numbers i picked

		}
	}

}
void genWinNum(int getNum[])

... but you're not putting anything into getNum[] in that function.
even thought I put something into getNum[]
It still show wrong random numbers

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
void* genWinNum(int getNum[])
{
	const int MAX_NUM = 40;
	const int MIN_NUM = 1;
	const int NUM = 7;
	int num[NUM];
	int* nums = num;
	srand(time(NULL));

	for(int i = 0; i < NUM; i++)
	{
		num[i] = (rand() % 40) + 1;// generate random number 1 to 40
		while(num[i] < 1 || num[i] > 40)// more than 40 and less than 1 is false
		{
			num[i] = (rand() % 10) + 1;// generate random number again till getting number between 1 to 40
		}
		if(i > 0)
		{
			for(int index = 0; index < i; index++)
			{
				while(num[i] == num[index])//generate number not to duplicate
				{
					num[i] = (rand() % 10) + 1;
				}
			}
		}
	}
	return nums;
}
Last edited on
Nope, your still not putting anything into getNum[]. You are putting random numbers into num[] instead.

You have passed into the function getNum[], so all you need to do is put your random numbers into that.
Last edited on
OH I got it!!!!
I didn't use getNum[] to be filled with the random number.
I only did it in just num[]
Thank you So much!!
Topic archived. No new replies allowed.