#include <iostream.h>
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include <math.h>
#include <fstream.h>

bool _bet()
{
	bool win = false, even, odd, zero;
	int result = rand()%37;

	even = (result%2==0);
	odd = (!even);
	zero = (result==0);

	if(zero)
		win=false;
	else
		if(odd)
			win=false;
		else
			win=true;

	return win;
}

main()
{
	srand(time(0));

	bool go=true;

	float start = 50, cash = start, bet=1;
	
	double standard, mean_standard;
	float mean_cash=start, mean_bet=bet, mean_profit=start, mean_mean_profit=0;
	int n=1, i=1, t=1;
	char win='L';

	
	for(;t<20;)
	{
	start+=10;
	for(i=1;i<50000;i++)
	{
		n=1; cash=start; bet=1;go=true;
//		cout<<"Bet No.  |  $ Bet  |  W/L  |  Cash After  |  Profit\n";		
		
		for(;go;)
		{
			go = ((cash<10000));
		
			if(go)
			{
				cash-=bet;
				if (_bet())
				{
					cash+=(2*bet);
					win='W';
				}else{win='L';}

//				cout<<"   "<<n<<"      "<<bet<<"         "<<win<<"          "<<cash<<"     "<<cash-start<<endl;
				
				n++;
				if(win)
					bet=float((bet*5));
			}
		}

		mean_cash+=cash;
		mean_bet+=bet;
		mean_profit+=(cash-start);
		standard+=pow((cash-start)-mean_mean_profit,2);	

	}	
	standard = sqrt(standard/i);
	mean_standard+=standard;
	mean_mean_profit+=(mean_profit/i);

//	cout<<"Mean Cash:  "<<mean_cash/i<<endl;
//	cout<<"Mean Bet:   "<<mean_bet/i<<endl;
//	cout<<"Mean Profit: "<<mean_profit/i<<endl<<endl;
//	cout<<"Standard Deviation: "<<mean_standard/t<<endl;
	cout<<start<<", Mean Mean Profit: "<<mean_mean_profit/t<<endl<<"--------------"<<endl;
	
	ofstream file("stats.txt", ios::out|ios::binary|ios::app);
	file<<mean_mean_profit/t<<endl;
	file.close();	

	mean_cash=mean_bet=mean_profit=standard=0;
	i=1;
//	int null=getchar();
	t++;
	}
	return 0;
}
