1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
|
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
//set variables
int choice;
double selection;
int where_drop = 0;
double user_winnings;
int randomizer;
int multiple_chips;
double selection_two;
int randomizer_two;
double user_winnings_two;
double average_winnings;
bool gameOn = true;
//make menu screen
while (gameOn != false){
cout << "***GAME MENU***\n";
cout << " 1 - Drop one chip into one slot.\n";
cout << " 2 - Drop multiple chips into one slot.\n";
cout << " 3 - Drop multiple chips into every slot. \n";
cout << " 4 - Exit.\n";
cout << " Enter your choice and press enter: ";
cin >> choice;
//menu choices below in switch
switch (choice)
{
case 1:
cout << "\n Which Slot would you like to Drop a chip in(Please enter a slot #0-8)?"<<"\n";
cin >> selection;
if((selection < 0) || (selection > 8))//if a negative number or greater than 8 go back to menu
{
break;
}
srand(time(0)); //seed the random number
for(int i=1; i<=12; i++ ) //12 iterations
{
randomizer = rand() % 2;
if (randomizer == 0)
{
selection += ( selection == 8 ) ? -0.5 : 0.5;
}
else
{
selection += ( selection == 0 ) ? 0.5 : -0.5;
}
cout << selection << endl; //print out the 12 drops of plinko
}
//find winnings. could of done array here.
int user_winnings[9] = {
100,
500,
1000,
0,
10000,
0,
1000,
500,
100
};
//print out winnings
cout<<"You've won $" << user_winnings << "!" << endl;
break;
case 2: //second option
cout << "\n How many chips would you like to play?"<<"\n";
cin >> multiple_chips;
if(multiple_chips < 0)//don't allow negative numbers
{
break;
}
cout << "\n Which Slots would you like to Drop the chip(s) into(Please enter a slot #0-8)?"<<"\n";
cin >> selection_two;
if((selection_two < 0) || (selection_two > 8))//only allow 0-8 as option or return to menu
{
break;
}
srand(time(0)); //seed the random number
for(int i=1; i<=12; i++) //12 iterations starting from 1
{
randomizer_two = rand() % 2;
if (randomizer_two == 0)
{
selection_two += ( selection_two == 8 ) ? -0.5 : 0.5;
}
else
{
selection_two += ( selection_two == 0 ) ? 0.5 : -0.5;
}
}
//find winnings. could of done array here.
int user_winnings_two[9] = {
100,
500,
1000,
0,
10000,
0,
1000,
500,
100
};
//final calculations
average_winnings = user_winnings_two / multiple_chips;
cout<<"You've won a total of $" << user_winnings_two << "!" << endl;
cout<<"You averaged winnings of $" << average_winnings << " a chip." << endl;
break;
case 4://quit program
cout << "End of Program.\n";
gameOn = false;
break;
default:
cout << "Not a Valid Choice. \n";
cout << "Choose again.\n";
break;
cin >> choice;
}
}
return 0;
}
|