I don't have any code, mainly because I haven't started working on this particular problem. It is for homework for my C Programming class.
My professor wants us to create a program that tosses a coin (heads or tails) 10,000 times. However, the heads element has a 55% chance to occur. We have to use a random number generator with a user-supplied seed
value.
Conceptually, I know how to approach this; coding-wise, I have no clue. I know how to make a coin tossing program, but not with a bias.
Any and all help would be appreciated.
I've attached code for my coin tosser program. I had intended to use this as a basis for this new bias coin tossing program.
// CoinTosser_Homework4.cpp : Coin tossing program
// nxt3
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#define HEADS 0
#define TAILS 1
int rand_int(int a, int b) {
return rand() % ((b - a + 1) + a);
}
int main() {
int tosses = 0, min = 0, heads = 0, tails = 0; //init tosses and number of user defined tosses
/*users input for number of tosses*/
printf("Enter number of coin tosses: ");
scanf("%i", &min);
while (tosses < min) {
tosses++;
if (rand_int(HEADS, TAILS) == HEADS)
heads++;
else
tails++;
}
//prints results of tosses
printf("Number of heads: %i\n", heads);
printf("Number of tails: %i\n", tails);
return 0;
}