Hey, I need to make a 'balls in a rolling cage' lottery game; it plays like this (from teacher's exemple):
-Program shows 2 numbers from 0 to 21 (let's call them number1a and number2a)
-Then, the user selects how many times he/she wants to roll the cage (containing the 'number balls')
-Program picks 2 random numbers from 0 to 21 (number1b and number2b)
-Then, the program checks if those two newly picked up numbers are the same as the first ones. (if number1a==number1b && number2a==number2b)
So if both numbers are the same (before and after the rolling), then the user wins.
If one number is picked again and the second is not, then the user loses.
ie:
Program picks up 7 and 19.
Program asks me how many rolls? I want it to roll 10x.
Program picks 7 and 19.
YAY! I won!
or...
Program picks 7 and 19.
Program asks me how many rolls? I want it to roll 100x.
Program picks 7 and 13. <=> Program picks 2 and 8.
Sorry, better luck next time.
The goal of using the rolling thing is that the more rolls you make, the less change you get the same numbers.
Hoping you guys understood the point this game , here's my current code:
Code:
// Lottery game
#include<iostream>
#include<cstdlib>
#include<ctime>
using std::cout;
using std::cin;
using std::endl;
int main()
{
double number1a, number2a, number1b, number2b, xRoll;
cout << "Welcome to the Lottery Game!" << endl << endl;
number1 = rand()%21+1;
number2 = rand()%21+1;
if (number1 == number2){
number1 = rand()%21+1;
number2 = rand()%21+1;
cout << "The first number is: " << number1a << endl;
cout << "The second number is: " << number2a << endl;
cout << "How many rolls?: " << xRoll;
[No idea what's next here...]
cout << "The first picked number is: " << number1b << endl;
cout << "The second picked number is: " << number2b << endl;
if (number1a == number1b && number2a == number2b){
cout << "CONGRATULATIONS! You won the lottery!" << endl;
}
else
cout << "Sorry, you lost. Better luck next time.";
}
else{
cout << "The first number is: " << number1 << endl;
cout << "The second number is: " << number2 << endl;
cout << "How many rolls?: " << xRoll;
[No idea what's next here...]
cout << "The first picked number is: " << number1b << endl;
cout << "The second picked number is: " << number2b << endl;
if (number1a == number1b && number2a == number2b){
cout << "CONGRATULATIONS! You won the lottery!" << endl;
}
else
cout << "Sorry, you lost. Better luck next time.";
}
return 0;
}
Sorry if it's bloated with useless lines...
Also, I keep getting the same picked numbers frequencies... like on the first play, i get numbers 2 and 11, then I close the program, re-open it, and it gives me 2 and 11 again on 2nd play. 3rd play, same thing...
I looked in my book and it suggests to use srand to generate new frequencies at each time. Tried that; no success
-Thanks in advance