Posted: Fri Feb 08, 2008 5:29 pm
Well thanks, but it is nothing really, also i see now that i have made a few abious mistakes.
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";
}