If you want to evaluate the experimental probability of a getting a full house, it would be helpful to examine more than one hand.

Solved

Posted on 2004-10-10

<code>

#include <stdio.h>

#include <stdlib.h>

#include <time.h>

const int n = 1000000; /* number of shuffles */

void Exchange(int* iPtr, int* jPtr);

char* Suit[4] = {"Spades", "Hearts", "Clubs", "Diamonds"};

char* CardValue[13] = {"Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King", "Ace"};

int main(void)

{

int Deck[52], Counter[13], i, j, m, r, k, FullHouse=0;

double t = clock();

/* ------ Initialize Deck ------ */

for (j=0; j<13; j++) {

Counter[j]=0; }

for (i=0; i<52; i++) {

Deck[i] = i; }

printf("the program is running\nthe first hand with a full house is:\n\n");

/* -------- Shuffle Deck ------- */

for (k=0; k<n; k++) {

for (i=51; i>0; i--) {

Exchange(&Deck[i], &Deck[rand()%(i + 1)]); }}

/* -------- Draw a Hand -------- */

for (m=0; m<5; m++) {

Counter[Deck[m]%13]++; }

/* --- Check for Full House ---- */

for (r=0; r<13; r++) {

if (Counter[r]==3) {

for (j=0; j<13;j++) {

if (Counter[j]==2) {

FullHouse++;

if (FullHouse==1) {

for (i=0; i<5; i++) {

printf("%s of %s\n", CardValue[Deck[i]%13], Suit[Deck[i]/13]); }}}}}}

for (j=0; j<13; j++) {

Counter[j]=0; }

t = clock() - t;

printf("\nthe experimental probability of two cards with the same value is %1f\n", (double)FullHouse/k);

printf("the time taken equals %f seconds\n", t/CLOCKS_PER_SEC);

return 0;

}

void Exchange(int* iPtr, int* jPtr) {

int k = *iPtr;

*iPtr = *jPtr;

*jPtr = k; }

</code>

The output that I am supposed to be getting is:

Three of Hearts

Three of Spades

Two of Spades

Three of Diamonds

Two of Hearts

the experimental probability of a full house is 0.001438

the time taken equals 3.423568 seconds.

Thanks

#include <stdio.h>

#include <stdlib.h>

#include <time.h>

const int n = 1000000; /* number of shuffles */

void Exchange(int* iPtr, int* jPtr);

char* Suit[4] = {"Spades", "Hearts", "Clubs", "Diamonds"};

char* CardValue[13] = {"Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King", "Ace"};

int main(void)

{

int Deck[52], Counter[13], i, j, m, r, k, FullHouse=0;

double t = clock();

/* ------ Initialize Deck ------ */

for (j=0; j<13; j++) {

Counter[j]=0; }

for (i=0; i<52; i++) {

Deck[i] = i; }

printf("the program is running\nthe first hand with a full house is:\n\n");

/* -------- Shuffle Deck ------- */

for (k=0; k<n; k++) {

for (i=51; i>0; i--) {

Exchange(&Deck[i], &Deck[rand()%(i + 1)]); }}

/* -------- Draw a Hand -------- */

for (m=0; m<5; m++) {

Counter[Deck[m]%13]++; }

/* --- Check for Full House ---- */

for (r=0; r<13; r++) {

if (Counter[r]==3) {

for (j=0; j<13;j++) {

if (Counter[j]==2) {

FullHouse++;

if (FullHouse==1) {

for (i=0; i<5; i++) {

printf("%s of %s\n", CardValue[Deck[i]%13], Suit[Deck[i]/13]); }}}}}}

for (j=0; j<13; j++) {

Counter[j]=0; }

t = clock() - t;

printf("\nthe experimental probability of two cards with the same value is %1f\n", (double)FullHouse/k);

printf("the time taken equals %f seconds\n", t/CLOCKS_PER_SEC);

return 0;

}

void Exchange(int* iPtr, int* jPtr) {

int k = *iPtr;

*iPtr = *jPtr;

*jPtr = k; }

</code>

The output that I am supposed to be getting is:

Three of Hearts

Three of Spades

Two of Spades

Three of Diamonds

Two of Hearts

the experimental probability of a full house is 0.001438

the time taken equals 3.423568 seconds.

Thanks

4 Comments

Comment Utility

The program shuffles the deck a million times and deals one hand. It doesn't report on that one hand unless it is a full house. The odds are that the hand will not be a full house, and so the program will not report its contents.

If you want to evaluate the experimental probability of a getting a full house, it would be helpful to examine more than one hand.

If you want to evaluate the experimental probability of a getting a full house, it would be helpful to examine more than one hand.

Comment Utility

I think you need an endless loop around all that code so it continues on even if the first hand isnt a full house.

Either that or you need to put a brick on the uparrow and enter keys.

Either that or you need to put a brick on the uparrow and enter keys.

Join the community of 500,000 technology professionals and ask your questions.

Connect with top rated Experts

**10** Experts available now in Live!