Hi everyone, I am having a problem to write a program that simulates a lottery. I hope someone can guide me to fix the problem/error step by step. Thank you.
Here is the question: The program should have an array of five integers named lottery, and should generate a random number in the range of 0 to 9 for each element in the array.
The user should enter five digits which should be stored in an integer array named user.
The program is to compare the corresponding elements in the two arrays and keep a count of the digits that match. For example, the following shows the lottery array and the user array with sample numbers stored in each. There are two matching digits (elements 2 and 4).
lottery array: 7, 4, 9, 1, 3
user array: 4, 2, 9, 7, 3
The program should display the random numbers stored in the lottery array and the number of matching digits. If all of the digits match, display a message proclaiming the user as a grand prize winner.
Your program must use the following functions:
void generateNumbers(int [ ], int);
void getUser(int [ ], int);
int findMatches(int [ ], int [ ], int);
void displayValues(int [ ], int [ ], int);
And here is my code:
Code:
.
// Chapter 7
// Assignment 7-Lottery Application.
#include <iostream>
#include <time.h>
using namespace std;
// Function prototype
void generateNumbers(int[], int);
void getUser(int[], int);
int findMatches(int[], int[], int);
void displayValues(int[], int[], int);
int main()
{
const int SIZE = 5; // Size of an array.
int lotteryArray[SIZE]; // To hold the lottery's number in randomly.
int userArray[SIZE]; // To hold the user's number.
// Function begin
cout << "This program can helps you win a lottery game." << endl;
// Get the number from lottery array.
generateNumbers(lotteryArray, SIZE);
// Get the number from user.
getUser(userArray, SIZE);
// Find and match the lottery and user array.
findMatches(lotteryArray, userArray, SIZE);
// Display a message.
displayValues(lotteryArray, userArray, SIZE);
system ("PAUSE");
return 0;
}
//*************************************************
// The message displays a generateNumbe function. *
// ************************************************
void generateNumbers(int lotteryArray[], int SIZE)
{
srand(time(0));
int randNum = rand() % 9+0; // Each elements in the array that genertate a randNum in the range of 0 - 9.
randNum = lotteryArray[0];
cout << "The lottery program will generate some random numbers "
<< "in the range of 0 to 9";
cout << "Here is " << SIZE << "element in the array";
cin >> randNum;
return 0;
}
//**********************************************
// This message displays a getUser function. *
//**********************************************
void getUser(int userArray[], int SIZE)
{
// Loop counter
int index;
for(index = 0; index < SIZE; index++)
{
cout << "Enter " << SIZE << "digits number to win the lottery: ";
cin >> userArray[index];
}
}
//**************************************************
// This message displays a findmatches function. *
//**************************************************
int findmatches(int lotteryArray[], int userArray[], int SIZE)
{
bool arraysEqual = true; // Flag variable.
int count = 0; // Loop counter varabile.
// Determine whether the elements contain the same data.
while (arraysEqual && count < SIZE)
{
if (lotteryArray[count] != userArray[count])
arraysEqual = false;
count++;
}
if (arraysEqual)
cout << "The arrays are match.\n";
else
cout << "The arrays are not match.\n";
return 0;
}
//**************************************************
// This message displays a displayValues function. *
//**************************************************
void displayValues(int lotteryArray[] , int userArray[], int SIZE)
{
int arraysEqual;
if(arraysEqual = false)
cout << "Sorry your numbers weren't match to the wining number, please try that again.\n";
else
cout << "Congratulations, you are a grand prize winner.\n";
}
.
Here are the problems that I got:
2010\projects\improve\improve\improve.cpp(46): warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
2010\projects\improve\improve\improve.cpp(57): error C2562: 'generateNumbers' : 'void' function returning a value
2010\projects\improve\improve\improve.cpp(8) : see declaration of 'generateNumbers'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========