Hello friends,
I have written some code for the game plinko. All of it works as expected and as required EXCEPT! there is an option to put multiple chips into any slot. Every time the multiple chips fall they almost always end up in the final slot of 0. I am trying to figure out why they always tend to favor landing in the 0 slot. Please help!!! thank you.
the path to follow in the code is:
2 //this takes you to the multiple chips
n chips // however many chips you want to drop
0-8 // what ever slot you want your chips to fall in.
#include <iostream>
#include <string>
#include <time.h>
#include <iomanip>
usingnamespace std;
int main() {
srand(time(0));
int ans;
int single = 1;
int multiple = 2;
int quit = 3;
//random number either 0 or 1
// 0= -.5
// 1= +.5
int bowl = 0;
double move_left = -.5;
double move_right = .5;
double winnings_zero = 100.00;
double winnings_one = 500.00;
double winnings_two = 1000.00;
double winnings_three = 0.00;
double winnings_four = 10000.00;
double winnings = 0;
double average_winnings = 0;
//Enter while the answer is anything but what is in the "quit" string, if the answer is equal then skip the loop.
while (true) {
double slot_start = 0.0;
cout << "MENU: Please select one of the following options:\n";
cout << "1 - Drop a single chip into one slot\n";
cout << "2 - Drop multiple chips into one slot\n";
cout << "3 - Quit the program\n";
cout << "Enter your selection now: ";
cin >> ans;
//Enter this if the answer is equal to the "single" string
if (ans == single) {
cout << fixed << setprecision(1);
cout << "***DROP SINGLE CHIP***\n";
cout << "Which slot do you want to drop the chip in (0-8)?\n";
cin >> slot_start;
if ((slot_start >= 0) & (slot_start <= 8)) {
cout << "[" << slot_start;
for (int i = 0; i < 12; i++) {
double direction = (rand() % 2);
//I = 12 This is for printing out the final Bracket at the end of the chip path.
if (i == 12){
//you cant fall off the board to the left
if (slot_start == 0.0) {
slot_start = slot_start + move_right;
}
//you cant fall off the board to the right!
elseif (slot_start == 8.0) {
slot_start = slot_start + move_left;
}
//you can play plinko though!!
else {
//move to the left one slot
if (direction == 0) {
slot_start = slot_start + move_left;
}
//move to the right one slot
if (direction == 1) {
slot_start = slot_start + move_right;
}
}
}
//I = 0-11
//you cant fall off the board to the left!
elseif (slot_start == 0.0) {
slot_start = slot_start + move_right;
}
//you cant fall off the board to the right!
elseif (slot_start == 8.0) {
slot_start = slot_start + move_left;
}
//you can play plinko though!!
else {
//move to the left one slot
if (direction == 0) {
slot_start = slot_start + move_left;
}
//move to the right one slot
if (direction == 1) {
slot_start = slot_start + move_right;
}
}
cout << " " << slot_start;
}//plinko ForLoop
cout << "]" << endl;
cout << fixed;
if (slot_start == 0 || slot_start == 8){
cout << setprecision(2) << "$" << winnings_zero << endl;
}
elseif (slot_start == 1 || slot_start == 7){
cout << setprecision(2) << "$" << winnings_one << endl;
}
elseif (slot_start == 2 || slot_start == 6){
cout << setprecision(2) << "$" << winnings_two << endl;
}
elseif (slot_start == 3 || slot_start == 5){
cout << setprecision(2) << "$" << winnings_three << endl;
}
else {
cout << setprecision(2) << "$" << winnings_four << endl;
}//slot_number check IfF(x)
}
else {
cout << "INVALID SLOT, slots 0-8.\n";
}
}
//Enter this IF the answer is equal to the "multiple" string.
elseif ((ans == multiple)) {
int slot = 0;
cout << "***DROP MULTIPLE CHIPS***\n";
cout << "How many chips do you want to drop >0?\n";
cin >> bowl;
if (bowl > 0) {
cout << "Which slot would you like to put your chips in?\n";
cin >> slot_start;
for (int i = bowl; i > 0; i--) {
slot = slot_start;
if ((slot >= 0) && (slot <= 8)) {
for (int i = 0; i < 12; i++) {
double direction = (rand() % 2);
//I = 12 This is for printing out the final Bracket at the end of the chip path.
if (i == 12){
//you cant fall off the board to the left
if (slot == 0.0) {
slot = slot + move_right;
}
//you cant fall off the board to the right!
elseif (slot == 8.0) {
slot = slot + move_left;
}
//you can play plinko though!!
else {
//move to the left one slot
if (direction == 0) {
slot = slot + move_left;
}
//move to the right one slot
elseif (direction == 1) {
slot = slot + move_right;
}
}
}
//I = 0-11
//you cant fall off the board to the left!
elseif (slot == 0.0) {
slot = slot + move_right;
}
//you cant fall off the board to the right!
elseif (slot == 8.0) {
slot = slot + move_left;
}
//you can play plinko though!!
else {
//move to the left one slot
if (direction == 0) {
slot = slot + move_left;
}
//move to the right one slot
elseif(direction == 1) {
slot = slot + move_right;
}
}
}//plinko ForLoop
cout << "thisistheslot" << slot << endl;
if (slot == 0 || slot == 8){
//cout << "Icamehere\n";
winnings = winnings + winnings_zero;
}
elseif (slot == 1 || slot == 7){
//cout << "Icamehere\n";
winnings = winnings + winnings_one;
}
elseif (slot == 2 || slot == 6){
//cout << "Icamehere\n";
winnings = winnings + winnings_two;
}
elseif (slot == 3 || slot == 5){
//cout << "Icamehere\n";
winnings = winnings + winnings_three;
}
else{
//cout << "Icamehere\n";
winnings = winnings + winnings_four;
}//slot_number check IfF(x)
//plinko ForLoop
}//plink if
else {
cout << "INVALID SLOT, slots 0-8.\n";
}
}
cout << fixed << setprecision(2) << "$" << winnings << endl;
cout << setprecision(2) << "$" << winnings / bowl << endl;
winnings = 0;
}
//for loop bowl#oftimes
else {
cout << "INVALID NUMBER OF CHIPS.\n";
}
}
elseif (ans == 3) {
cout << "GOODBYE\n";
system("pause");
return 0;
}
//Print if user does not enter "1", "2", or "3"
else {
cout << "INVALID SELECTION, Please enter 1, 2 or 3.\n";
}
//Reprompt the user after a running single chip, multiple chips, or receiving invalid data.
}
cout << "GOODBYE\n";
}