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
|
#include <ctime>
#include <iostream>
#include <sstream>
#include <string.h>
#include <random>
using namespace std;
class TripleString
{
string string1, string2, string3;
public:
static const int MAX_LEN=20;
TripleString();
bool validString( string str );
void set(string str1, string str2, string str3);
string get(int strPosition);
};
TripleString::TripleString()
{
string1="";
string2="";
string3="";
}
bool TripleString::validString(string str)
{
if (str.length()<=MAX_LEN)
return true;
return false;
}
void TripleString::set(string str1, string str2, string str3)
{
if(validString(str1))
{
string1=str1;
}
if(validString(str2))
{
string2=str2;
}
if(validString(str3))
{
string3=str3;
}
}
string TripleString::get(int pos)
{
if(pos==1)
{
return string1;
}
if(pos==2)
{
return string2;
}
if(pos==3)
{
return string3;
}
}
int getBet();
TripleString pull();
string randString();
int getPayMultiplier (TripleString thePull);
void display (TripleString thePull, int winnings );
int main()
{
srand( time( NULL ) );//seed for rand method
TripleString thePull;
int bet, mult, winnings;
//string mult, bet;
bet = getBet();
//stringstream convert(bet);
//if ( !(convert >> int_bet) )
if(bet==0)
return 0;
thePull=pull();
mult = getPayMultiplier(thePull);
//stringstream convert(mult);
//if ( !(convert >> int_mult) )
winnings=mult*bet;
display(thePull, winnings);
}
int getBet()
{
int betAmount;
cout<<"enter bet amount (1-100), entering a zero will terminate the program: ";
cin>>betAmount;
if(betAmount==0)
{
return 0;
}
else if(betAmount>=1 && betAmount<=100)
{
return betAmount;
}
do
{
cout<<"invalid bet. please bet between 1 and 100: ";
cin>>betAmount;
}
while(betAmount>100||betAmount<0);
}
TripleString pull()
{
TripleString pullResult;
cout<<"Whirrrrrrrr....and your pull is...."<<endl;
pullResult.set(randString(),randString(),randString());
return pullResult;
}
string randString()
{
int randNum;
randNum=rand()%100+1;
if(randNum<=50)//20000*50=10000
return "BAR";
else if(randNum>50 && randNum<=75)//20000*25=5000
return "cherries";
else if(randNum>75 && randNum <=87)//20000*12.5=2500
return "space";
else if(randNum>87 && randNum <=100)//20000*12.5=2500
return "7";
}
int getPayMultiplier (TripleString thePull)
{
if(thePull.get(1)=="cherries" && thePull.get(2)!="cherries")
{
return 5;
}
else if(thePull.get(1)=="cherries" && thePull.get(2)=="cherries" && thePull.get(3)!="cherries")
{
return 15;
}
else if(thePull.get(1)=="cherries" && thePull.get(2)=="cherries" && thePull.get(3)=="cherries")
{
return 30;
}
else if(thePull.get(1)=="BAR" && thePull.get(2)=="BAR" && thePull.get(3)=="BAR")
{
return 50;
}
else if(thePull.get(1)=="7" && thePull.get(2)=="7" && thePull.get(3)=="7")
{
return 100;
}
else
{
return 0;
}
void display (TripleString thePull, int winnings );
{
//winnings = mult*bet;
cout<<thePull.get(1)<<" "<<thePull.get(2)<<" "<<thePull.get(3)<<endl;
if( winnings != 0)
{
cout<<"Congratulations! You won "<<winnings<<"!"<<endl;
}
else
{
cout<<"Sorry, you lose..."<<endl;
}
}
}
|