Question: Coin toss in C code using time.h and stdlib.h headers, and rand and srand(time(NULL)) to create 1 for heads or 2 for tails. The user

Coin toss in C code using time.h and stdlib.h headers, and rand and srand(time(NULL)) to create 1 for heads or 2 for tails. The user enters how many times they want the coin tossed, then the number of heads and tails tossed is displayed, and the percentage of heads and tails. Include the use of 1 symbolic constant in program.

Unsure how to put the rest together.

I have so far:

#include stdio.h

#include time.h

#include stdlib.h

#define PERCENT 100 //symbolic constant

int main()

{

//declare variables

int tosses;

int heads;

int tails;

float headsPercent;

float tailsPercent;

int x;

for(x=0; x

intrand()%2+1;

rand()

srand(time(NULL))

printf("Coin Toss");

printf("How many times to toss the coin?: ");

scanf("%d", tosses);

tailsPercent = tosses/heads * PERCENT;

headsPercent = tosses/tails * PERCENT;

printf("There were", heads "and", tails);

printf("The percentage of heads was %%.2", floatHeads "and" "%%.2" floatTails);

}

thanks-

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!