Hi, I need help writing a program for the powerball game.
so this is what i have so far. I am having difficulties in comparing the numbers generated and the numbers entered by the user. This is what i have so far.

``````#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int GetNum (int[], int);
int GetPower (int);
int whiteBall (int[], int);
int redBall (int);
int searchNumber (int[], int size, int value);

int main()
{
int results1, results2, results3, results4, results5;
const int max = 5;
int PowerNum, PowerNum1;
int UserFive1[5],  UserFive[5];

GetNum (UserFive, max);
GetPower (PowerNum);
whiteBall(UserFive1, max);
redBall (PowerNum1);

return 0;

}

//*********************************************************
// Function that lets user enter five numbers (white ball)*
//*********************************************************

int GetNum (int five[], int MAX)
{
MAX = 5;

for (int i=1; i<=MAX; i++)
{
int numTemp;
cout << "Enter number " << i  << endl;
cin >>  numTemp;
five[i] = numTemp;
cout << five[i];

if(numTemp<1 || numTemp>59)
{
cout << "The number you entered does not fall in range. Please enter another number for " << i;
cin >> numTemp;
}

else if ( five[0] == five[1] )

{
cout << "Please enter another number for your second number : " << endl;
cin >> five[1];
}
else if ( five[1] == five[2])
{
cout << "Please enter another number for your third number : " << endl;
cin >> five[2];
}
else 	if ( five[2] == five[3] )

{
cout << "Please enter another number for your fourth number : " << endl;
cin >> five[3];
}
else	if ( five[3] == five[4] )

{
cout << "Please enter another number for your fifth number : " << endl;
cin >> five[4];
}
}

return five[MAX];
}

//****************************************************
// Function that lets the user enter the power number*
//****************************************************

int GetPower (int PowNum)
{
cout << "Enter the number for power ball " << endl;
cin >> PowNum;
if (PowNum<1 || PowNum>39)
{
cout <<" The number you have entered is wrong. Please enter another number." <<endl;
cin >> PowNum;
}
return PowNum;
}

//************************************************
// Function that generates the five random number*
//************************************************

int whiteBall(int WhiteNum[], int MAX)

{
srand(time(0));
int MAX = 5;

for(int i = 1; i <= MAX; i++){

WhiteNum[i] = 1 + rand() % 59;

}
return WhiteNum[MAX];
}

//************************************************
// Function that generates the power ball number *
//************************************************

int redBall (int powerball)

{
srand(time(0));

powerball = 1+ rand() %39;
return powerball;
}

//***********************************************
// Function that searches for numbers that match*
//***********************************************
int searchNumber (int array[], int size, int value)
{
int first = 0,
last =size -1,
middle,
position = -1;
bool found = false;
int MAX =5;
for (int i = 1; i<=5; i++)
{

while (!found && first <= last)
{
middle = (first +last )/ 2;
if (array[middle] == value)
{
found = true ;
position = middle;
}
else if (array[middle] > value)
last = middle -1;
else
first = middle + 1;
}
}
return position;
}``````

I have noticed a few different things that you might want to fix about the program, aside from the problem you've mentioned:

• The code formatting is very inconsistent; I recommend you be more careful about it. This page is a good reference for how to style your code in a readable manner.
• You should only call `srand()` once, at the beginning of the program; by putting it in the randomizer function, you are calling it every time you use it, and if the calls are very close together, they may end up with the same seed (and hence the same 'random' number).
• The five `results*` variables in your `main()` function are redundant; you can remove them entirely.
• Since you want to be able to match the numbers regardless of the order they appear, you would be better off sorting the numbers first, then comparing them in order. This would simplify the comparison considerably, as you'd only need to check up to the number being sought.
Be a part of the DaniWeb community

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