The program asks the user to provide from 1 to 6, inclusive, numbers between 1 and 59, inclusive, as their lotto numbers. The lotto program will then use the random number generator to provide the same number of numbers in the same range. Check to see how many of the numbers match by comparing the contents of both arrays. If less than the quantity of numbers match, start over with another set of newly-generated random numbers. Keep track of how many sets of numbers (your “lottery drawings”) need to be generated before a perfect match of all the numbers is found.

Her is a list of the function prototypes that should be used in the program:

//Function Prototypes
void initArrays (int a[], int b[], int c); 
int getNumberOfPicks (void); 
void getUsersNumbers (int a [], int b);
void fillRandomArray (int a[], int b);
bool compareArrays (int a[], int b[], int c);
void printResults (int a[], int b, int c);

This is what I have so far;

int main ()
{	
	int numLot, i;
	
	

	cout << "This program simulates a lottery game. Warning: finding matches for" << endl;
	cout << "just 3 numbers may require 100's of thousands of lottery drawings!" << endl;

	do
	{
		cout << "\nPlease enter the number of lottery numbers to be played from 1 to 6: ";
		cin >> numLot;
		if (numLot > 6 || numLot < 1)
		{
			cout << "Error, number out of range--please enter agian:"<< endl;
		}
		else
			break;
	}
	while (1);

	do
	{  
     cout << "Enter a number: ";  
     cin >> choices[i];
     i++;
	}
	while(i < numLot);



	cin.ignore();//flush input buffer



	getchar ();


}

What's your question?

@jkoske: You know what the question is. It's "I've done a little bit of my homework; will you do the rest for me?" The answer is (or should be) no.

You are missing return 0; at the bottom of your main function.

The question I'm asking is how do I implement the functions into my list, I did not ask anyone to do it for me, therefore the snide remark from arkoenig is not neccesary, I understand how daniweb works. Im having trouble understanding which array function will I need to use to store the original inputs from the user

@sfuo I used getchar(); along with the flush input buffer which achieves the same task as the return keyword

You know what? When you say that you did not ask anyone to do it for me, you are technically correct--but I don't believe you.

Look at what you posted. It was a paragraph that is expressed in a way that looks like it was literally copied from a homework assignment, and it said nothing about what kind of assistance you were seeking. So there are two possibilities:

1) You wanted someone to finish the incomplete solution that you posted, or

2) You wanted someone to read your mind and figure out what question(s) you wanted to ask.

But now that you've asked a question, I'll answer it. You asked "which array function will I need to use to store the original inputs from the user."

Well, C++ doesn't have anything called an array function, so far as I know, so I'm going to guess that you mean which of the functions you listed at the beginning of your example. Let's take a look at those functions' names and signatures, and see if we can figure out what they ought to do.

First, there's initArrays. It takes two pointers and an int (when you declare a function parameter with [], it's really just an alternative way of declaring a pointer). I think it is a reasonable guess that the int is the size of the two arrays, that both arrays are the same size, and, from its name, the function is supposed to initialize them--that is, set them to the first values that they are intended to have.

getNumberOfPicks is a function with no parameters, yet it returns an int. It must get that int from somewhere, and from its name, it seems reasonable to assume that it is intended to ask the user for that value.

getUsersNumbers takes two arguments, a pointer and an int. From its name, I figure it must be intended to read a bunch of numbers from the user. The int probably tells how many numbers and the pointer is the address of the first element of an array that is intended to hold the numbers.

OK, I've done half of them. You do the other half.

I apologize for the misunderstanding, my intentions were not to get anyone to do my homework for me and I did not expect anyone to do so. But, I will admit in my vagueness I did hope a little that somebody would show me how the function definitions are written and for that I apologize again.
The design specifications came from my class notes, I did not copy them, I just wanted to create some context to which the program is intended to achieve.
I am sorry for the misconception and I am also sorry if I offended you in any way and I appreciate that you did decide to help me despite the circumstances.

Now, with that behind us, here is my question:
In line 25 I used a do while loop to store the numbers the user selected into the array choices []. however after declaring the array (which isn't shown in the program above) I received a pointer type error. How can I pass an array into a function that hasn't been initialized until the user inputs the integers?

I'm sorry, but I don't understand the question. You can't pass an array to a function; you can only pass a pointer to one of its elements (usually the first one). So for example, if you execute the following:

int* p = new int[n];
fun(p);
delete[] p;

you are allocating an array with n elements and setting p to point at its first element. Then you call fun with that pointer as its argument. Finally, after fun returns, you deallocate the array and return its memory to the system.

If this doesn't point you in the direction of doing what you want, then I'm afraid you'll have to explain it more clearly.

Sorry I having trouble understanding how the functions work so I tried a diffrent avenue and I have the user input numbers between 1 and 59 for the array choices [] but I have run into an issue validating the numbers and moving to the next statement in the loop

int main ()
{	
	int numLot, count;
	int choices [6];
	
	

	cout << "This program simulates a lottery game. Warning: finding matches for" << endl;
	cout << "just 3 numbers may require 100's of thousands of lottery drawings!" << endl;

	do
	{
		cout << "\nPlease enter the number of lottery numbers to be played from 1 to 6: ";
		cin >> numLot;
		if (numLot > 6 || numLot < 1)
		{
			cout << "Error, number out of range--please enter agian:"<< endl;
		}
		else
			break;
	}
	while (1);

	cout << "\nPlease enter " << numLot << " lottery numbers";

	count = 0;
	while (count < numLot)
	{
		cout << "Enter a number between 1 and 59: " << endl;
		cin >> choices[6];
		if (choices [6] > 59 || choices [6] < 1)
		{
			cout << "Error, number out of range--please enter agian:"<< endl;
	    }
		else 
		count ++;

	}

	return (0);


}

Your array "choices" has 6 elements. That means that the first element is choices[0] and the last element is choices[5]. So lines 30 and 31 are invalid, because they attempt to access an element of choices that does not exist.

ohh I see, so I was trying to access index 6 which doesn't exist, so when I was trying to put numbers in the array from the while loop, I was storing data in index 6 instead of storing numbers in the array choices []. How would I accomplish putting data inputted from the user into the array then?

I fixed the issue and got the program to store in values for the array

count = 0;
	while (count < numLot)
	{
		cout << "\nEnter a number between 1 and 59: ";
		cin >> choices[count];
		if (choices [count] > 59 || choices [count] < 1)
		{
			cout << "Error, number out of range--please enter agian:"<< endl;
	    }
		else 
		count ++;

	}

My next step is to display the numbers that the user inputted into the array

cout << endl;

	cout << "The numbers matched were";

	for (count = 0; count < numLot; count++) // Print array choices [] lottery picks
	cout << " " << choices[count];

	cout << endl;

I've reached the point of no return now I must use functions to create a reference array. At first, I'll not use the RNG to fill the reference array. I will initialize it with known values so I can check the development of my algorithm. When I think I'm on the right track, I'll use the RNG to create random numbers for my array.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.