Created
March 2, 2012 21:12
-
-
Save eligundry/1961446 to your computer and use it in GitHub Desktop.
Lottery Lap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <ctime> | |
#include <cstdlib> | |
using namespace std; | |
void initalize(int array[], int size, int val); | |
int check(int array[], int size, int val); | |
void draw(int array[], int size); | |
void entry(int& guess); | |
void printOut(int array[], int size, int& guess, int winner); | |
int main() | |
{ | |
const int size = 10; | |
int intval = -1; | |
int wins[size]; | |
int guess = 0; | |
initalize(wins, size, intval); | |
draw(wins, size); | |
entry(guess); | |
int winner = check(wins, size, guess); | |
printOut(wins, size, guess, winner); | |
return 0; | |
} | |
void initalize(int array[], int size, int val) | |
{ | |
for (int i = 0; i < size; ++i) { | |
array[i] = val; | |
} | |
} | |
int check(int array[], int size, int val) | |
{ | |
for (int i = 0; i < size; ++i) { | |
if (array[i] == val) { | |
return i; | |
} | |
} | |
return -1; | |
} | |
void draw(int array[], int size) | |
{ | |
srand(time(NULL)); | |
int random = rand() % 100; | |
for (int i = 0, j = 0; i < size; ++i, j = 0) { | |
random = rand() % 100; | |
do { | |
if (array[j] != random) { | |
++j; | |
} else { | |
random = rand() % 100; | |
j = 0; | |
} | |
} while (j <= i); | |
array[i] = random; | |
} | |
} | |
void entry(int& guess) | |
{ | |
cout << "Please enter a single number, 0-99, for your lottery entry: "; | |
cin >> guess; | |
} | |
void printOut(int array[], int size, int& guess, int winner) | |
{ | |
cout << endl << "Results of the Lottery" << endl << "Lottery Numbers: "; | |
for (int i = 0; i < size; ++i) { | |
cout << array[i] << " "; | |
} | |
cout << endl << "Your guess: " << guess << endl; | |
if (winner >= 0) { | |
cout << "YOU WON THE LOTTERY!!! ZOMG!!!" << endl; | |
} else { | |
cout << "You lost the lottery. Oh well." << endl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment