Premium domains
- AndrewAPrice
- Member
- Posts: 2299
- Joined: Mon Jun 05, 2006 11:00 pm
- Location: USA (and Australia)
I wrote a matingale simulator in C++ that takes into account 0 and 00.
Code: Select all
#include <iostream>
#include <time.h>
// play a game of roulette - returns true if game won
bool PlayRoulette()
{
int number = rand() % 38; // 0 and 00
if(number == 0)
{
std::cout << "Rolled 00 (lost).\n";
return false;
}
else if(number < 2 || number % 2)
{
std::cout << "Rolled " << number - 1 << " (lost).\n";
return false;
}
std::cout << "Rolled " << number - 1 << " (won)!.\n";
return true;
}
void main()
{
int money, minimumbet, numberofrounds = 0;
std::cout << "Enter starting amount: $";
std::cin >> money;
std::cout << "Enter minimum bet: $";
std::cin >> minimumbet;
std::cout << "Enter number of rounds to play: ";
std::cin >> numberofrounds;
int mostmoneyeverhad = money;
int biggestbet = minimumbet;
srand((unsigned int)time(0));
int currentbet = minimumbet;
while(numberofrounds-- && (money - currentbet) > 0)
{
money -= currentbet;
std::cout << "Betting $" << currentbet << ": ($" << money << " )";
if(PlayRoulette())
{
money += currentbet * 2;
currentbet = minimumbet;
if(money > mostmoneyeverhad)
mostmoneyeverhad = money;
}
else
{
currentbet *= 2;
if(currentbet > biggestbet)
biggestbet = currentbet;
}
}
std::cout << "\n------------\nEnded playing spree.";
std::cout << "Most money ever: $" << mostmoneyeverhad << "\n";
std::cout << "Largest bet made: $" << biggestbet << "\n";
std::cout << "Current money: $" << money;
if(money <= 0)
std::cout << "(BANKRUPT!)\n";
else if(money - currentbet <= 0)
std::cout << " (Not enough money to make bet.)\n";
else
std::cout << "\n";
}
Last edited by AndrewAPrice on Tue Feb 12, 2008 7:17 am, edited 1 time in total.
My OS is Perception.
- AndrewAPrice
- Member
- Posts: 2299
- Joined: Mon Jun 05, 2006 11:00 pm
- Location: USA (and Australia)
oops! That should say 38, thanks!
It'd be cool to see a roulette simulator that simulates actual ball physics.
It'd be cool to see a roulette simulator that simulates actual ball physics.
My OS is Perception.
- AndrewAPrice
- Member
- Posts: 2299
- Joined: Mon Jun 05, 2006 11:00 pm
- Location: USA (and Australia)
You could do this betting system but change the multiplier. e.g. 2.5x or 3x instead of the standard 2x.
Or even a variable multiplier which starts out at 4x and slowly lowers to 2x when it reaches $50.
Or even a variable multiplier which starts out at 4x and slowly lowers to 2x when it reaches $50.
My OS is Perception.