0

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;
}
```

*Edited 5 Years Ago by Madbabe*: n/a