Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- //prototyping for custom function
- int coinFlipper(void);
- int main()
- {
- //intializes tracking variables
- float flips = 1.0;
- float heads = 0.0;
- float tails = 0.0;
- //intializes placeholder for custom function
- int test = 0;
- //loop to track the number of flips
- for (int counter = 0; counter <= 5; counter++)
- {
- //multiplies flips to increase the # of flips
- flips *= 10.0;
- //resets deads/tails count at start of loop
- heads = 0.0;
- tails = 0.0;
- for (int i = 0; i < flips; i++)
- {
- //assigns variable test to the return value of coinFlipper()
- test = coinFlipper();
- //checks if coinFlipper output is even
- if (test % 2 == 0){
- //If yes, +1 to heads
- ++heads;
- }
- //If no, +1 to tails
- else{
- ++tails;
- }
- }
- //outputs the results to the user
- printf("\nNumber of Flips: %.f\n", flips);
- printf("\nResults:\n");
- printf("\nHeads: %.f || %.2f percent\n", heads, heads / flips * 100); //conversion for percentage
- printf("\nTails: %.f || %.2f percent\n\n", tails, tails / flips * 100); //conversion for percentage
- printf("\n------------------------\n\n");
- }
- system("pause");
- return 0;
- }
- //custom function to generate random int
- int coinFlipper(void)
- {
- int num = rand() % 100;
- return(num);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement