Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdbool.h>
- #include <time.h>
- #define SCENARIO_COUNT 1000
- bool fiftyFifty();
- int main()
- {
- srand(time(NULL));
- bool firstFlip, secondFlip;
- int scenariosRun, hhCount=0, htCount=0, ttCount=0;
- for(scenariosRun = 0; scenariosRun < SCENARIO_COUNT; scenariosRun++)
- {
- firstFlip = fiftyFifty(); //both flips are 50/50
- secondFlip= fiftyFifty();
- if(!firstFlip && !secondFlip)
- {
- ttCount++;
- }
- while(!firstFlip && !secondFlip) //check for TT
- {
- firstFlip = fiftyFifty(); //flip both coins again as long as both are TT
- secondFlip= fiftyFifty();
- }
- if(firstFlip && secondFlip) //if both coins are heads, this counter goes up
- {
- hhCount++;
- }
- if(!firstFlip || !secondFlip) //if either coin is tails, this counter goes up
- {
- htCount++;
- }
- }
- //print results
- printf("Results gathered from %d scenarios in which one heads is guaranteed:", scenariosRun);
- printf("\nTimes both were heads: %d", hhCount);
- printf("\nTimes one was heads: %d", htCount);
- printf("\nTT reflips: %d", ttCount);
- return 0;
- }
- bool fiftyFifty()
- {
- int isCrit = rand() % 2;
- if (isCrit == 1)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement