Feb 12, 2013 at 2:02am UTC
All i need help with is the bottom portion... I do not understand or it is difficult for me to write code?? I am writing code for a lotto simulation, the code is self-explanatory until the bottom portion. How do I fix the bottom portion to tell the user what they won or if they won??
I think I got pretty much of the code, but I need help on the bottom. How do i define user and lottery.. Confused!! Also code is confusing so help also...
//Declarations
#include <iostream>
#include <cstdlib>
#include <ctime>
const int lotteryDigits = 10;
const int SIZE = 5;
const int Power = 1;
int generateLottery(int[], int, int);
int powerBall(int[], int);
int userInput(int[], int);
int count1= 0;
int matchCounter(int[], int[], int);
void displayNumbers(int[], int[]);
void displayhotball (int[], int[]);
void winnerOrLoser(int);
bool matches = true;
using namespace std;
int main()
{
int lottery[5] = {0, 0, 0, 0, 0};
int user[5] = {0, 0, 0, 0, 0};
int ball[1] = {0};
int matches = 0;
generateLottery(lottery, SIZE, lotteryDigits);
userInput(user, SIZE);
matchCounter(lottery, user, matches);
displayNumbers(lottery, user);
displayhotball(ball, user);
winnerOrLoser(matches);
system ("pause");
return 0;
}
//Randomly generates winning lottery numbers and power numer
int generateLottery(int lottery[], int, int)
{
unsigned seed = time(0);
srand(seed);
for (int y=0; y<SIZE; y++)
{
lottery[y] = rand() % lotteryDigits;
}
return lottery[0], lottery[1], lottery[2], lottery[3], lottery[4];
}
int powerBall(int ball[], int)
{
unsigned seed = time(0);
srand(seed);
int x;
for (x=0; x<Power; x++);
{
ball[x]= rand() % SIZE;
}
return ball[0];
}
//Reads user lottery number choices
int userInput(int user[], int)
{
for (int count1=0; count1<SIZE; count1++)
{
cout<<"Enter a digit between 0 and 9:--->";
cin>> user[count1];
while (user[count1]<0 || user[count1]>9)
{
cout<<" Error! Entry must be between 0 and 9--->";
cin>> user[count1];
}
}
for( int count1=0; count1<Power; count1++)
{
cout<<"Enter a hot power number between 0 and 5--->";
cin>> user[count1];
while (user[count1]<0 || user[count1]>5)
{
cout<<" Error! Entry must be between 0 and 5--->";
cin>> user[count1];
}
}
return 0;
}// end userInput
// Counts the number of matches
int matchCounter(int lotto [], int input[], int)
{
int match = 0;
for (int x = 0; x < SIZE; ++x)
{
if (lotto[x] == input[x])
match = match + 1;
}
return match;
}
//Displays the winning numbers and the user's number
void displayNumbers(int lottery[], int user[])
{
cout << "\nThe winning lottery numbers are: " << lottery[0] <<" "<< lottery[1]<<" "<< lottery[2]<<" "<<lottery[3]<<" "<<lottery[4]<< endl;
cout << "Your lottery numbers are: " << user[0] << " " << user[1] << " " << user[2] << " " << user[3] << " " << user[4] << endl;
}
//Displays Power Number
void displayhotball(int ball[], int user[])
{
cout << "\nHot Winning Number:" << ball[0]<< endl;
cout<< "Your hot number is:" << user[0]<< endl;
}
//Determines matches
void winnerOrLoser(int matches)
{
for (matches = 0; matches < SIZE; matches++)
{
while (matches < SIZE)
{
if (user[count1] != lottery[count1])
matches = false;
count1++;
}
cout << "You matched " << matches << " numbers";
if (matches != SIZE)
cout << "\nSorry--you lose. Better luck next time.\n";
else if (matches == Power)
cout << "\nCongratulations--you win $4!!!!\n";
else if (matches== 1&&Power)
cout<<"\nYou win $4\n";
else if (matches == 2)
cout<<"\nYou win $7\n";
else if (matches == 2&&Power)
cout<<"\nYou win $7\n";
else if (matches == 3)
cout<<"\nYou win $7\n";
else if (matches == 3&&Power)
cout<<"\nYou win $100\n";
else if (matches == 4)
cout<<"\nYou win $100\n";
else if (matches == 4&&Power)
cout<<"\nYou win $10000\n";
else if (matches == 5)
cout<<"\nYou win $100000\n";
else ( matches == SIZE);
cout<< "\nYou win $2,000,000\n";
}