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 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314
|
#include <iostream>
#include <cmath>
#include <string>
#include <cstdlib>
#include <iomanip>
#include <ctime>
#include <math.h>
#include <stdio.h>
using namespace std;
//Prize Money Function
double get_prize_money(double location)
{
int slotnumber = 0;// declare some variables
int chipnumber = 0;
double reward = 0;
const double PRZ0 = 100;
const double PRZ1 = 500;
const double PRZ2 = 1000;
const double PRZ3 = 0;
const double PRZ4 = 10000;
const double PRZ5 = 0;
const double PRZ6 = 1000;
const double PRZ7 = 500;
const double PRZ8 = 100;
const int PRICE_PRECISION = 2;
const int PATH_PRECISION = 1;
const int RIGHT_WALL = 8;
const int LEFT_WALL = 0;
const int SLOT_1 = 1;
const int SLOT_2 = 2;
const int SLOT_3 = 3;
const int SLOT_4 = 4;
const int SLOT_5 = 5;
const int SLOT_6 = 6;
const int SLOT_7 = 7;
if (location == LEFT_WALL) { reward = PRZ0; }// if statements to determine winnings
else if (location == SLOT_1) { reward = PRZ1; }
else if (location == SLOT_2) { reward = PRZ2; }
else if (location == SLOT_3) { reward = PRZ3; }
else if (location == SLOT_4) { reward = PRZ4; }
else if (location == SLOT_5) { reward = PRZ5; }
else if (location == SLOT_6) { reward = PRZ6; }
else if (location == SLOT_7) { reward = PRZ7; }
else if (location == RIGHT_WALL) { reward = PRZ8; }
return reward;
}
//Single Chip Function
double single_chip(int slotnumber, int chipnumber)
{
double location = slotnumber;
const int PATH_PRECISION = 1;
const double MOVE = 0.5;
const int RIGHT_WALL = 8;
const int LEFT_WALL = 0;
const int BOARD_SIZE = 12;
if (slotnumber >= 0 && slotnumber <= 8)
{
if (chipnumber == 1)
{
cout << fixed << setprecision(PATH_PRECISION) << location;
}
for (int i = 0; i < BOARD_SIZE; i++)
{
double random = rand() % 2;
if (random < 1)
{
location = location + MOVE;
}
else
{
location = location - MOVE;
}
if (location < LEFT_WALL)
{
location = LEFT_WALL + MOVE;
}
else if (location > RIGHT_WALL)
{
location = RIGHT_WALL - MOVE;
}
if (chipnumber == 1)
{
cout << " " << location;
}
}
//cout << "]" << endl;
}
return location;//return final position
}
double single_chip_no_path(int slotnumber)
{
double location = slotnumber;
const double MOVE = 0.5;
const int RIGHT_WALL = 8;
const int LEFT_WALL = 0;
const int BOARD_SIZE = 12;
if (slotnumber >= LEFT_WALL && slotnumber <= RIGHT_WALL)
{
for (int i = 0; i < BOARD_SIZE; i++)
{
double random = rand() % 2;
if (random < 1)
{
location = location + MOVE;
}
else
{
location = location - MOVE;
}
if (location < LEFT_WALL)
{
location = LEFT_WALL + MOVE; ;
}
else if (location > RIGHT_WALL)
{
location = RIGHT_WALL - MOVE;
}
}
}
return get_prize_money(location);//return final position
}
//Mulitple Chip Function
void multiple_chips(int slotnumber, int chipnumber)
{
double winnings = 0;
double totalwinnings = 0;
const int RIGHT_WALL = 8;
const int LEFT_WALL = 0;
for (int i = 0; i < chipnumber; i++)
{
winnings = single_chip_no_path(slotnumber);
totalwinnings = totalwinnings + winnings;
}
double average = totalwinnings / chipnumber;
cout << endl << "Slot" << slotnumber << endl;
cout << "Average winnings per Chip: $" << average << endl;
cout << "Total winnings: $" << fixed << setprecision(2) << totalwinnings << endl;
}
//Multiple Chip Function in all Slots
void all_slots(int chipnumber)
{
const int RIGHT_WALL = 8;
const int LEFT_WALL = 0;
for (int i = LEFT_WALL; i <= RIGHT_WALL; i++)
{
multiple_chips(i, chipnumber);
//cout << "Slot " << slot_number << endl;
}
}
//Print Menu function
void print_menu()
{
cout << "Welcome to the Plinko simulator!" << endl;
cout << "Please enter one of the following options to continue: \n\tDrop One (1)\n\tDrop Multiple (2)\n\tDrop Multiple into all the slots (3)\n\tQuit (0): ";
}
//Main Function
const int RIGHT_WALL = 8;
const int LEFT_WALL = 0;
const int PRICE_PRECISION = 2;
const int PATH_PRECISION = 1;
const int QUIT = 0;
const int SINGLE_CHIP = 1;
const int MULTIPLE_CHIPS = 2;
const int MULTIPLE_CHIPS_ALL = 3;
const int BLASTED_ONE_THOUSAND = 1000;
int main()
{
int menu = 1;
bool done = false;
int menuoption = 0;
int slotnumber = 0;// declare some variables
int chipnumber = 0;
const int RIGHT_WALL = 8;
const int LEFT_WALL = 0;
double reward = 0;
double location = 0;
srand(time(0));
while (!done)
{
//cout << "Please enter one of the following options to continue: \n\tDrop One (1)\n\tDrop Multiple (2)\n\tDrop Multiple into all the slots (3)\n\tQuit (0): ";
print_menu();
cin >> menuoption;
if ( menuoption == SINGLE_CHIP || menuoption == MULTIPLE_CHIPS || menuoption == MULTIPLE_CHIPS_ALL || menuoption == QUIT )
{
//cin.clear();
//cin.ignore(1000, '\n');
//cout << "INVALID SLOT, please try again. " << endl << endl;
if (menuoption == QUIT) {
cout << "Goodbye and Good Riddance!" << endl;
done = true;
}
else if (menuoption == SINGLE_CHIP)// single chip
{
chipnumber = 1;
cout << "Select a slot (0-8): ";
cin >> slotnumber;
if (slotnumber < LEFT_WALL || slotnumber > RIGHT_WALL || cin.fail())
{
cin.clear();
cin.ignore(BLASTED_ONE_THOUSAND, '\n');
cout << "INVALID SLOT, please try again. " << endl << endl;
}
if (slotnumber >= LEFT_WALL && slotnumber <= RIGHT_WALL) //for loop to simulate random falling of chip
{
cout << "[";
location = single_chip(slotnumber, chipnumber);
cout << fixed << setprecision(PRICE_PRECISION) << "]" << endl << "Winnings: $" << get_prize_money(location) << endl;
cout << endl << endl << endl;
}
}
else if (menuoption == MULTIPLE_CHIPS)// multiple chips options
{
cout << "Please enter the number of chips to drop: ";//multiple chips input
cin >> chipnumber;
if (chipnumber < LEFT_WALL || cin.fail())
{
cin.clear();
cin.ignore(BLASTED_ONE_THOUSAND, '\n');
cout << "INVALID SLOT, please try again. " << endl << endl;
}
if (chipnumber > LEFT_WALL)
{
cout << "Select a slot (0-8): ";
cin >> slotnumber;
if (slotnumber < LEFT_WALL || slotnumber > RIGHT_WALL || cin.fail())
{
cin.clear();
cin.ignore(BLASTED_ONE_THOUSAND, '\n');
cout << "INVALID SLOT, please try again. " << endl << endl;
}
else if (slotnumber >= LEFT_WALL && slotnumber <= RIGHT_WALL)
{
multiple_chips(slotnumber, chipnumber);
cout << endl << endl << endl;
}
}
}
else if (menuoption == MULTIPLE_CHIPS_ALL)// multiple chips into all the slots
{
cout << "Please enter the number of chips to drop: ";//multiple chips input
cin >> chipnumber;
if (cin.fail())
{
cin.clear();
cin.ignore(BLASTED_ONE_THOUSAND, '\n');
cout << "INVALID SLOT, please try again. " << endl << endl;
}
else if (chipnumber < LEFT_WALL)
{
cin.clear();
cin.ignore(BLASTED_ONE_THOUSAND, '\n');
cout << "INVALID SLOT, please try again. " << endl << endl;
}
else all_slots(chipnumber);
cout << endl;
}
}
else if (menuoption != SINGLE_CHIP && menuoption != MULTIPLE_CHIPS && menuoption != MULTIPLE_CHIPS_ALL && menuoption != QUIT || cin.fail())
{
cin.clear();
cin.ignore(BLASTED_ONE_THOUSAND, '\n');
cout << "INVALID INPUT, Please enter 0, 1, 2, 3. " << endl << endl;
}
}
system("pause");
return(0);
}
|