Pointers are declared like this:
int *name;//it can be int/char/long int/uint...anything, but the amount it can store depends on the type of pointer it is
Once you declare a pointer in this manner, it is not pointing at anything useful. It is pointing to some random place in memory. So for you to make use of a pointer especially with an array, there are a couple ways I know how. First is the way I had started with but you have to give it something to point to.
int array[3] = {'A', 'B', 'C'};//An array with 0,1,2 spaces to store things in and the 3rd spot is to store the '\0' (NULL) value.
Now to make use of our pointer:
*name = array;//Now the pointer is pointing to the first value in our array array[0] (A)
Pointers declared this way are always pointing to the first value in the array unless otherwise specified i.e.
*name = array[2];//Now it will be pointing to the value 'C'
We can do useful things with this pointer now that it is pointing at something.
ex:
1 2 3 4 5 6 7
|
for (int y = 0; y < 3; y++, name++)
cout>> *name >> " "
//Now this will go ahead and print all the values in our array (A B C)
//You will notice that I did something like this: name++
//This is another beauty of pointers is that you can move them around to point
// to different things including other arrays or values! So specifying name++
// means to move the pointer to the next value in the array
|
A second way to use pointers will be to have a dynamically allocated array which is I think what you will most likely need. So instead of creating a pointer and an array, we can have both in one. Observe:
int *arr = new int[Enter_a_size_here];
And to access it, you can access it like a normal array or like a pointer, whichever you choose.
So we can do:
arr[0] = 5;
Or
*arr = 5;//This means the same thing as the above
E:
The first function you have to declare is quite easy. You are just required to output some instructions to the user at the start of the game. cout, printf, puts, etc will work for that.
void GetPlayerSelections (int *);
This function is being passed a pointer to an array. Declaring a dynamically allocated array in your main() can be useful because you can easily access it's elements in another function.
void GeneratePowerball (int *);
Same thing applies from above. So you need another array to be passed to the function where it will place randomly generated numbers into the array.
int CheckForWin (int *, int *);
This will go through both arrays and check that array[n] = array2[n]. If it finds no such match, it will return 0
int DisplayPrize (int );
This is being passed a number, I persume from the function before it and it is to display a prize depending on what value it was passed. The odds can be done with simple math.
This will all be run in one while-loop until the player has spent all of his tokens
Hope that helps, gl