## C#

Moderators: None (Apply to moderate this forum)
Number of posts: 5749

This Forum Only

solved Posted by jacobcyh on 24 May 2009 at 4:35 AM
Hi all.

I'm new to C# and i'm trying to create a program that simulates Martingale's system of coin toss betting.

Problems i'm facing now:

1)Generating fair coin tosses with the Random function
2)Comparing the current toss with the previous tosses to invoke Methods

I've read through several beginners guides and know the basics, but I cant find anything specific to these problems highlighted above.

Any help would be greatly appreciated.

Thanks!

-solved-
Re: solved Posted by Psightoplazm on 26 May 2009 at 8:11 AM
So the betting theory assumes a ficticious better with an infinite amount of money. It is based on the theory that the flip of a coin will always eventually even itself out. The betting method is to start with a bet - let's say 1 dollar - and then double it every time you lose. This way you eventually make back all of your money lost, plus profit.

Am I remembering that right?

Try this...

```Random rnd = new Random();
double bet = 1.0;
double winnings = 0.0;

do
{
Console.WriteLine("Current Winnings: " + winnings);
Console.WriteLine("Betting " + bet + " on heads:");
Console.WriteLine("Press any key to proceed...");
var flip = rnd.Next(100);// 100 gives us a more even chance
if (flip >= 50)
{
Console.WriteLine("Winner!");
winnings += bet;
}
else
{
Console.WriteLine("Loser!");
winnings -= bet;
bet *= 2;
}
} while(true);

```

></\/~Psightoplasm`~

## Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic