Nov 30, 2013 (last update: Dec 4, 2013)

# Powerball lottery Simulator

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262`` ``````// // PowerBall.cpp // // Created by Leonardo Rocha on 11/29/13. // Copyright (c) 2013 Leonardo Rocha. All rights reserved. // #include #include #include using namespace std; //Function Protoypes void setSeed(); //This will set the seed for the random numbers int randomWhiteNumber(); //This will get a random number 1-59 int randomRedNumber(); //This will get a random number 1-35 bool checkArray(int [], int, int); //This will check to see if a random number has already been found int displayMenu(); //This will display the intro menu and let the user buy tickets int won(int, bool); //This function determines how much money a ticket won //global constants const int SIZE = 6; //This is the number of balls per ticket const int MAX_WHITE = 58; //This is the range of the white balls const int MAX_RED = 34; //This is the range of the red balls const int waysToWin = 9; int main(int argc, const char * argv[]) { int tickets = displayMenu(); //Welcome screen lets you buy tickets int spending = tickets * 2; //Charges you for the tickets int randomTickets[tickets][SIZE]; //Ticket number holders int randomPowerNumber[SIZE]; //Power ball numbers int arrayHolder[SIZE]; //Temporary ticket holder int ballCounter = 0; //Keeps track of winning balls in a ticket bool redBall; //Keeps track if the red ball matches int cashWon = 0; //Cash won Accumalator int lost = 0; int winningTickets[waysToWin]; setSeed(); //Sets random seed /* The next set of instructions will randomly generates the first 5 white balls and the last ball is the red ball White balls are 1-59 and the red ball are 1-35 */ cout<<"Powerballs: "; for(int i = 0; i>tickets; while((tickets <= 0 || tickets > 250000)) { cout<<"Please enter a number between 1-1000: "; cin>>tickets; } return tickets; } /**************************************************************************** * setSeed() * * The set Seed function sets the seed for the rand function * ***************************************************************************/ void setSeed() { long seed; seed = time(0); unsigned int sseed = static_cast(seed); srand(sseed); } /**************************************************************************** * randomWhiteNumber() * * The function will generate a number 1-59 and return the number * ***************************************************************************/ int randomWhiteNumber() { int randomVar = (rand() % MAX_WHITE)+1; return randomVar; } /**************************************************************************** * randomRedNumber() * * The function will generate a number 1-35 and return the number * ***************************************************************************/ int randomRedNumber() { int randomVar = (rand() % MAX_RED)+1; return randomVar; } /**************************************************************************** * checkArray() * * This function will search through array[] for a number if the number * * is found then return true if it is not found return false * ***************************************************************************/ bool checkArray(int array[], int size, int number) { bool has = false; for(int i = 0; i< size; i++) { if(array[i] == number) { has = true; } } return has; } /**************************************************************************** * won() * * This functions compare the number of balls that match in a ticket * * and returns the amount of cash the ticket is worth * ***************************************************************************/ int won(int ballCount, bool redBall) { int cash = 0; switch(ballCount) { case 5: if(redBall) cash = 70000000; else cash = 1000000; break; case 4: if(redBall) cash = 10000; else cash = 100; break; case 3: if(redBall) cash = 100; else cash = 7; break; case 2: if(redBall) cash = 7; else cash = 0; break; case 1: if(redBall) cash = 4; else cash = 0; break; default: if(redBall) cash = 4; else cash =0; break; } return cash; }``````