Comparing 5 numbers chosen to 5 random numbers

I'm working on a program where I have to create a game where the user selects 5 numbers from 0-9 to bet on. The five numbers are then compared to 5 random numbers generated. If the user gets 2 of the 5 numbers correct, they break even, if they get 3 of the 5 correct, they get double the bet, 4 correct is triple the bet, and if they get all, then they get ten times their bet. The issue I'm having problems with is making it so that there aren't double random numbers and I honestly don't know how to compare the numbers and determine which numbers they matched up with.

Here's the code that I have for the game so far. I've tried using a[j], but it didn't work out, probably because I'm not using it correctly.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
void pickfive::game()
{
	int i, j, first, second, third, fourth, fifth;
	srand(time(NULL));
	for (i = 1; i < times; i++)
	{
		cout << "~~~~~ Pick 5 Game #" << i++ << "~~~~~" << endl;
		cout << "How much would you like to bet?" << endl;
		cin >> bet;
		cout << "Pick 5 numbers from 0-9" << endl;
		cin >> first, second, third, fourth, fifth;

		for(j = 0; j < 5; j++)
		{
			int x = rand() % 5 + 1;
			cout << "Random Number " << x << endl;
		}
	}
}
I'm a C++ beginner but I'm going to try talking this out.
Okay so let's say the user picks 1,2,3,4,5.
First =1, Second =2, etc.
Then what you want to do is compare each picked number with a set of random numbers.
I believe the way that you have your j loop set up, even if you were to compare the picked numbers, x would constantly change value.
I think you need to create an array of integers for random numbers, that way the set will stay constant so you can compare each number.
int randomnumberarray[5].
Then
1
2
for (int j = 0; j < 5; j++)
randomnumberarray[j] = rand() % 5+1
;

I'm not sure whether or not this particular syntax is valid.

This way randomnumberarray[0], randomnumberarray[1], etc are assigned values.
Then I think you can use either if statements or for loops to compare the picked numbers with the random numbers.
And if they are the same number then keep a count of it.
Then you can use the count to multiple their initial bet.
so have like
int betcount =0;

Perhaps something like
1
2
3
4
5
6
if (first == randomnumberarry[0] || first == randomnumberarray[1] || etc)
betcount++
else
if (second == randomnumberarray[0] || second == randomnumberarray[1] etc)
betcount++
etc.


This may work but I'm just doing a lot of hand waving.
Last edited on
Topic archived. No new replies allowed.