California Lotto C++ Computer Software Simulation
http://answers.yahoo.com/question/index;_ylt=AkspTyFQ9UcDkCFhKqunJ2IjzKIX;_ylv=3?qid=20081215200527AAD7ajB
C++ program assignment ?
this is my assignment for class not to sure how to start it. can someone give me some ideas?
Super LOTTO Simulation
The “heart and guts” of any game is the random number generator.
Using the Random, write a simulation that will "play" the California Super LOTTO. Your program logic will allow the player to:
1) Pick any 6 integer numbers from 1 - 55. Your logic should prevent the player from selecting a value LESS than 1 or greater than 55. The logic should prevent the player from selecting the SAME number (i.e. they cannot have two or more of their selections be the SAME number).
2) Display the players' 6 number selections on the CRT screen.
3) Use the built in rand function to draw 6 numbers. This is the simulated "balls" being picked by LOTTO (i.e. ball = rand()% max_num + 1;). You will also need to set the seed for the random number algorithm:
srand( (unsigned)time( NULL ) );
4) Determine the number of "matches" (those numbers that the player picked that matches those that LOTTO drew).
5) If you matched 0, 1 or 2 numbers, you win NO money (but print some message such as "our schools WIN.").
6) We’ll dispense with a Mega Number. You would probably wish to put the logic in some sort of loop to ask the user whether they wish to play again (clearing out the previous variables and arrays?)
· If you match 3 numbers, you win $5.00.
· If you match 4 numbers, you win $36.00.
· If you match 5 numbers, you win $1,000.00 to $25,000.00 dollars (i.e. random(25) + 1 ).
· If you match 6 numbers (NONE of them the BONUS) you win $1 million to $100 million dollar (i.e. random(100) ).
Tactical Hints:
1. Use a pair of one dimensional arrays of size 56. We “ignore” subscript 0, leaving 1 - 55. One array will "hold" the 6 numbers the player picked. The other array "holds" the numbers LOTTO drew. Set all array location values of both arrays to 0. Set the VALUE of one array’s location index location to 1 if the player selected the number (i.e. they picked 2, therefore ARRAY subscript index location 2 has value 1). Set the other array's location's value to 1 if LOTTO drew that number.
2. Compare both arrays to determine if a match occurred. If the same subscript location on both arrays holds a 1, a match occurred. Use for loops to search through the arrays.
3. Use a switch statement to determine the prize won based on the number of matches. The number of matches is an integer.
4. There is a “harder” way to do this with an array of 6 numbers each (Using two full size 56 arrays is the “straight ahead, brute force approach with no finesse”, the easier method to comprehend).
Super LOTTO Simulation
The “heart and guts” of any game is the random number generator.
Using the Random, write a simulation that will "play" the California Super LOTTO. Your program logic will allow the player to:
1) Pick any 6 integer numbers from 1 - 55. Your logic should prevent the player from selecting a value LESS than 1 or greater than 55. The logic should prevent the player from selecting the SAME number (i.e. they cannot have two or more of their selections be the SAME number).
2) Display the players' 6 number selections on the CRT screen.
3) Use the built in rand function to draw 6 numbers. This is the simulated "balls" being picked by LOTTO (i.e. ball = rand()% max_num + 1;). You will also need to set the seed for the random number algorithm:
srand( (unsigned)time( NULL ) );
4) Determine the number of "matches" (those numbers that the player picked that matches those that LOTTO drew).
5) If you matched 0, 1 or 2 numbers, you win NO money (but print some message such as "our schools WIN.").
6) We’ll dispense with a Mega Number. You would probably wish to put the logic in some sort of loop to ask the user whether they wish to play again (clearing out the previous variables and arrays?)
· If you match 3 numbers, you win $5.00.
· If you match 4 numbers, you win $36.00.
· If you match 5 numbers, you win $1,000.00 to $25,000.00 dollars (i.e. random(25) + 1 ).
· If you match 6 numbers (NONE of them the BONUS) you win $1 million to $100 million dollar (i.e. random(100) ).
Tactical Hints:
1. Use a pair of one dimensional arrays of size 56. We “ignore” subscript 0, leaving 1 - 55. One array will "hold" the 6 numbers the player picked. The other array "holds" the numbers LOTTO drew. Set all array location values of both arrays to 0. Set the VALUE of one array’s location index location to 1 if the player selected the number (i.e. they picked 2, therefore ARRAY subscript index location 2 has value 1). Set the other array's location's value to 1 if LOTTO drew that number.
2. Compare both arrays to determine if a match occurred. If the same subscript location on both arrays holds a 1, a match occurred. Use for loops to search through the arrays.
3. Use a switch statement to determine the prize won based on the number of matches. The number of matches is an integer.
4. There is a “harder” way to do this with an array of 6 numbers each (Using two full size 56 arrays is the “straight ahead, brute force approach with no finesse”, the easier method to comprehend).
Comments
Post a Comment