So I got some good help from my last post!!
(
http://www.cplusplus.com/forum/beginner/79921/)
And was able to figure out my problem!
But now I've ran into a few more....
Again, looking for hints, or syntax I should look up, or something.
Now, the program is broken basically into 3 parts.
A - dropping 1 token in the plinko machine and show your winnings
B - dropping multiple tokens in the same slot of the plinko machine then report the total average $ of those tokens.
C - Exit the program
So I have A and C working (I know, using goto statements is considered taboo, but I already had most of it written when they changed the originally assignment on me, so I just threw in some goto's)
I'm working on part B.
I can't seem to figure out how to throw multiple coins, into the same slot, and then compare their winnings. I was trying to do a loop inside of a loop. So basically trying to run part A x amount of times (depending on user input).
Anyhow, would love if you could take a look. If you have any further questions, contact me.
Thanks!
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
|
#include <iostream>
#include <math.h>
#include <string>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <cstdlib>
#include <ctime>
using namespace std;
int main(){
double pz0 = 100;
double pz1 = 500;
double pz2 = 1000;
double pz3 = 0;
double pz4 = 10000;
double pz5 = 0;
double pz6 = 1000;
double pz7 = 500;
double pz8 = 100;
string option_select;
double slot;
string yes_no;
srand (time(0));
double mult_token;
double mult_slot;
cout <<"******** PLINKO SIMULATOR ********\n\n";
cout <<"Please select from the following options:\n";
cout <<"A: Drop one token\n";
cout <<"B: Drop multiple tokens\n";
cout <<"C: Quit the program\n";
cin >> option_select;
goto program;
start:
cout <<"\n\nThat was an invalid inplut\n";
cout <<"******** PLINKO SIMULATOR ********\n\n";
cout <<"Please select from the following options:\n";
cout <<"A: Drop one token\n";
cout <<"B: Drop multiple tokens\n";
cout <<"C: Quit the program\n";
cin >> option_select;
// Part A
program:
if (option_select != "A" && option_select !="a" && option_select !="B"
&& option_select !="b" && option_select !="C" && option_select !="c")
{
cout <<"**That is not a valid input, please try again**\n\n";
cout <<"******** PLINKO SIMULATOR ********\n\n";
cout <<"Please select from the following options:\n";
cout <<"A: Drop one token\n";
cout <<"B: Drop multiple tokens\n";
cout <<"C: Quit the program\n";
cin >> option_select;
}
if (option_select == "A" || option_select == "a")
{
cout <<"\nThere are 8 slots in which you can drop your token!\n";
cout <<"In which slot will we be dropping your token?\n";
cout <<"Slot: ";
cin >> slot;
while (slot >=9 || slot <= -1)
{
goto start;
}
if (slot <=8 || slot >=0)
{
double pos = slot;
for (int i=1; i<=12; i++)
{
double plink = (rand () %2) -0.5;
pos = pos + plink;
if (pos > 8)
{
pos = pos - 1.0 ;
}
if (pos < 0)
{
pos = pos + 1.0;
}
cout << pos << " **PLINK** \n" << endl;
}
cout << "You landed at: " << pos << endl;
if (pos == 0)
{
cout << "You win: " << pz0;
}
else if (pos == 1)
{
cout << "You win: " << pz1;
}
else if (pos == 2)
{
cout << "You win: " << pz2;
}
else if (pos == 3)
{
cout << "You win: " <<pz3;
}
else if (pos == 4)
{
cout << "You win: " <<pz4;
}
else if (pos == 5)
{
cout << "You win: " <<pz5;
}
else if (pos == 6)
{
cout << "You win: " <<pz6;
}
else if (pos == 7)
{
cout << "You win: " <<pz7;
}
else if (pos == 8)
{
cout << "You win: " <<pz8;
}
cout << " ";
}
}
//B's options
if (option_select == "B" || option_select == "b")
{
cout << "\nHow many tokens would you like to drop? ";
cin >> mult_token;
while (mult_token <= 0)
{
goto start;
}
cout << "\nIn which slot (0 - 8) would you like to drop your " << mult_token << " token(s)? ";
cin >> mult_slot;
while (mult_slot >=9 || mult_slot <= -1)
{
goto start;
}
if (mult_token >= 0 && mult_slot <=8 && mult_slot >=0)
{
for (int s=1; s=mult_token; s++)
{
for (int i=1; i<=12; i++)
{
double pos = mult_slot;
double plink = (rand () %2) -0.5;
pos = pos + plink;
if (pos > 8)
{
pos = pos - 1.0 ;
}
if (pos < 0)
{
pos = pos + 1.0;
}
cout << pos << " **PLINK** \n" << endl;
}
}
}
//C's option
if (option_select == "C" || option_select == "c")
{
end:
cout <<"\n\n****************************************\n";
cout <<"May the odds forever be in your favor!!!\n";
cout <<"****************************************\n\n";
}
return 0;
}}
|