I finally got around to converting this to a digital format so enjoy.
Background:
During the Christmas Holidays, I was playing poker with my family. Now when I say poker I generally mean Texas Hold’em, as this is the most widely know and, in my opinion at least, the easiest to learn and the most enjoyable to play. We never really, really gamble, just pass out some chips and play till you bust. It was while playing that I thought, if we did decide to have a buy-in how would we determine how to break it down. The question and problem led the way to the program I call, PPD, or Poker Pot Divider.
Analysis (please note that this analysis was written for C programming):
First off I want to say that the code below does not work, and I have not had the time to fix all the bugs.
Problem: To build a program that given the number of players and the buy-in amount, will display pot divisions by first, second, and third.
Sample Softcopy (note: all underlined data is to indicate a user input):
Welcome to the Poker Pot Divider (PPD)
Please enter the buy-in amount:10
Please enter the number of players:12
1st place – 65
2nd place – 35
3rd place – 20
In the code below I used a total of 9 variables and two functions:
Buyin- string total
Increase- string first values from buyin
h- the amount added onto a and b only
a- first place
b- second place
c- third place
PD- counter holder
P- amount of players
n- buyin amount
Adding()
Main()
Before I can explain the function Adding(), I need to show what h is. h is a value that will hold a number based on what Increase and PD is. Increase will copy the second number of Buyin with the command:
strncpy (Increase[ ], Buyin[ ], 1);
Then we will calculate the total number of placeholders in Buyin:
if (isdigit (Buyin[])) PD = PD + 1;
We can now find what h is. As I said earlier h is determined by what Increase and PD is. A chart I wrote looks like this:
0-10 = .5
11-199 = 5
200 – 1,999 = 55
2000- 19,999 = 555
20,000 – 199,999 = 5,555
200,000 – 199,999 = 55,555
2,000,000 – 10,000,000 = 555,555
Now this may seems weird and unnecessary, but I intend to make my approach more clear. We will return to the example given for our soft copy. If a equals 60 before adding h then it will equal 65 after; b will equal 35; c 20. A nice evenly distributed pot. H will be calculated by the computer using an if statement like the following:
if (PD >= 3 && PD <= 4 && Increase[ ] >= 2)
{
h=55;
Adding();
}
Adding is where I stored the math for this problem, and is as follows:
Buyin / 2 = a
a / 2 = b
a + h = a
b + h = b
-1(b + a) + Buyin = c
Okay, now the explanation. It is important that the computer performs this series of problems in this order. I will break it down for you. Lets us say that Buyin equals 120. This means that a is equal to 60 and b is equal to 30. We then add h and we arrive at 65 and 35 for a,b. Then we add them together and multiply by a negative and use the formula a + b = c. And we have our answers.
The last thing I will add to this post is the source code that I wrote and DID NOT WORK:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int Buyin[8];
int Increase[1];
double h,
a,
b,
c;
int PD = 0;
int P;
int n;
int dumby;
void Adding(void);
int main (void)
{
printf (”Welcome to the Poker Pot Maker (PPM)\n”);
printf (”Please enter a Buy-In amount (no decimals): “);
scanf (”%d”, &n);
printf (”\nPlease enter the number of players: “);
scanf (”%d”, &P);
/* Math */
Buyin[] = n * P;
strncpy (Increase[], Buyin[], 1);
if (isdigit (Buyin[])) PD = PD + 1;
if (PD >= 1 && PD <= 2)
{
h = .5;
Adding();
}
else if (PD >= 2 && PD <= 3)
{
h = 5;
Adding();
}
else if (PD >= 3 && PD <= 4 && Increase[1] >= 2)
h = 55;
Adding();
}
else if (PD >= 4 && PD <= 5 && Increase[1] >= 3)
{
h = 555;
Adding();
}
else if (PD >= 5 && PD <= 6 && Increase[1] >= 4);
{
h = 5555;
Adding();
}
else if (PD >= 6 && PD <= 7 && Increase[1] >= 5);
{
h = 55555;
Adding();
}
else if (PD >= 7 && PD <= 8 && Increase[1] >= 6);
{
h = 555555;
Adding();
}
printf (”\n\n1st place receives %lf.\n”, a);
printf (”2nd place receives %lf.\n”, b);
printf (”3rd place receives %lf.\n”, c);
printf (”-Press any key to exit-”);
scanf (”%d”, dumby);
}
void Adding(void)
{
a = Buyin / 2;
b = a / 2;
a = a + h;
b = b + h;
c = -1 * (b + a) + Buyin;
}