Lottery Code

Write your question here.
This is my CSC102 hw, i need help in knowing what to do?
Write a program to simulate the lottery. The program should work as follows and be sure to divide the program into functions that perform each task. You must use the provided prototypes and match the sample text exactly. Note, you do not need to worry about ensuring that the 5 values chosen (either by the computer or player) are unique.

Write a function to generate the computers lottery picks and store them in an array. The computer picks 5 numbers between 0 and 9.

void lotteryPicks(int lottery[], const int LENGTH);

Write a function to ask the user for their lottery pics. The user must enter in 5 numbers between 0 and 9. If the user enters invalid input, they should be pestered until they enter valid input.

void userPicks(int user[], const int Length);

Example 1:

Pick a number: 1
Pick a number: 2
Pick a number: 3
Pick a number: 4
Pick a number: 5

Example 2:

Pick a number: -2
Must be between (0,9): 2
Pick a number: 99
Must be between (0,9): 92
Must be between (0,9): 2
Pick a number: 3
Pick a number: 4
Pick a number: 5

Write a function to print out the computer's choice.

void displayLottery(int lottery[], const int LENGTH);

The function should print the following:

The winning numbers are 3, 4, 5, 7, 8.

Note: This is the output when the lottery contains {3, 4, 5, 7, 8}

Write a function to count the number of matches between the winning numbers and the players ticket. Only count repeating elements for once. For example, if the user array is {1, 2, 1, 3, 5} and the lottery is {3, 4, 9, 0, 1}, then there are only 2 (1 and 3) matches. The function must return the number of matches.

int matchCount(int lottery[], int user[], const int LENGTH);

Write a function to tell the user if they won or lost.

void checkWin(int matches, const int LENGTH);

Winning output:

Congrats on winning the grand prize!

Losing output:

Sorry that you didn't win!

Write a function to play a full game. It should also display the number of matching values:

void playLotto();

The function should have the following outputs:

Winning output:

Pick a number: 4
Pick a number: 2
Pick a number: 6
Pick a number: 1
Pick a number: 9
The winning numbers are 4, 1, 9, 6, 2.
The number of matching digits is 5.
Congrats on winning the grand prize!

Losing output:

Pick a number: 1
Pick a number: 2
Pick a number: 3
Pick a number: 5
Pick a number: 7
The winning numbers are 0, 6, 9, 3, 8.
The number of matching digits is 1.
Sorry that you didn't win!

Submit only the functions (no main) for this homework.

Note: You must match the output exactly (including spelling, capitalization, punctuation, and spacing). I will not answer emails unless they clearly demonstrate that all the directions were followed.

What have you written so far?
so far i have written:
#include <iostream>
using namespace std;

//Prototypes:
void lotteryPicks(int lottery[], const int LENGTH);
void userPicks(int user[], const int Length);
void displayLottery(int lottery[], const int LENGTH);
int matchCount(int lottery[], int user[], const int LENGTH);
void checkWin(int matches, const int LENGTH);

int main () {




return 0;}

//Functions:

i do not know which other libraries i need to access
not do i know how to do each of these functions

can you help me start of?
Please use code tags:
http://www.cplusplus.com/articles/jEywvCM9/

Start by writing the parts of your program that will do input and output with the user.

You don't need to know how to implement the functions yet, but you can still write their definitions and just leave them empty for now.
Last edited on
#include <cstdlib>
#include <ctime>
#include <iostream>
using namespace std ;

int main()
{
int i, j, k, nums[50] ; // declaring three variables and an array for fifty integers

srand( (int) time(0) ) ; // seed the random number generator with the current time

for( i = 1 ; i < 50 ; i++ ) nums[ i ] = i ; // Fill array elements 1-49 with integers 1-49

for( i = 1 ; i < 50 ; i++ )
{
j = ( (int) rand() % 49 ) + 1 ;
k = nums[i]; nums[i]= nums[j] ; nums[j] = k ;
}

cout << "Your six lucky numbers are: " ; \\ now output the values in array elements
for( i = 1 ; i < 7 ; i++ ) cout << nums[i] << " " ;

// Uncomment the lines below to see all element values.
// cout << endl << endl ;
// for( i = 1 ; i < 50 ; i++ ) cout<< i <<": "<< nums[i] << endl ;

return 0 ;
}


Might help with part of it, you may need to change the numbers to what you
want.
Last edited on
thank you for your help, thus far, however i have written my code like this
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

//Prototypes:
void lotteryPicks(int lottery[], const int LENGTH);
void userPicks(int user[], const int Length);
void displayLottery(int lottery[], const int LENGTH);
int matchCount(int lottery[], int user[], const int LENGTH);
void checkWin(int matches, const int LENGTH);
void playLotto();

int main () {


return 0;
}

//Functions:
void lotteryPicks(int lottery[], const int LENGTH) {
srand(time(0));
for (int i=0; i<LENGTH; i++){
lottery [i]=rand ()%10;
}
}

void userPicks (int user [],const int Length) {
int temp;
for (int i=0; i<Length; i++) {
cout<<"Pick a number ";
cin>>temp;
// validate input between 0 and 9
while (!((temp<=9)&&(temp>=0))){
cout<<"Must be between (0,9): ";
cin>>temp;
}
user[i]=temp;
}
}

void displayLottery(int lottery[], const int LENGTH) {
for (int i=0; i<LENGTH; i++){
cout<<lottery[i];
if (i<LENGTH-1)
cout<<",_,";
else
cout<<".";
}
}

int matchCount(int lottery[], int user[], const int LENGTH) {
}

void checkWin(int matches, const int LENGTH) {
}

void playLotto() {
}

i still need help completing the last three functions
Topic archived. No new replies allowed.