Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program in stdio.h!!!! NOT ios stream... but in stdio.h! I can only use those preset codes! Need it ASAP thank you! it is

Write a program in stdio.h!!!! NOT ios stream... but in stdio.h! I can only use those preset codes! Need it ASAP thank you! it is for visual studios 2012!!

image text in transcribed

Very short description: Write a program that simulates a coin tossing game for 2 players. The program should toss the coin 100 times. Ask the other player after each toss to guess the toss and then output the aggregate of Heads or Tails' guess made. More detailed description: The program should allow the players to choose if they want to player 1 or player 2. The player 1 has the first go. Player 1 then tosses the coin and asks player 2 to make the guess if it is 'Heads or Tails'. If the guess is right, then player2 gets awarded 10 pts. If the guess is wrong then the player loses 5 pts (-5pts). At the end of 100 tosses, calculate the confidence %, and display a formatted result as the example below Trials#of Heads #of Tails Player! Score Player2 Score 30% (1500) 100 50 50 70% (3500) Write a function toss to enable player to flip the coin. toss takes no input and outputs 1 for Heads and 0 for Tails. Write a function guess to ask a player to guess if the toss was Heads or Tails by inputting 'H' for Heads and 'T' for Tails. guess takes in no inputs from main0 and returns for Heads and 0 for Tails. Write a function confidence to calculate the percentage of right guesses made by players. For example: If player I guesses right 35 out of 50 times then his confidence% is 70%. Note that out of 100 coin tosses, each player gets 50 times each to toss and to guess. If your program simulates a realistic coin toss, then out of the 100 tosses, you should have 50 heads and 50 tails. The player with highest score is declared the winner and gets a congratulatory message as "Well done!!! Player X is the Winner!" To simulate the coin toss, the program must generate a random number from 0 to 1 for each toss for Tails and Heads respectively. To generate a random number, C provides the rand0 function However, this function is a pseudo-random number generator. The very first time the rand(O function is called, it will come up with the same number (not exactly what you want). Therefore to give the rand function a different starting point each time, we can initialize the random generator with the time0 function, which returns the number of seconds from the system clock. In other words, do the following at the beginning of your program srand(unsigned)time(NULL) // only needs to be done once Iseed random function with current time Student Name Section: 03 Date You need to include stdlib.h (i.e., #include ) to use the rand() and srand() functions and time.h for the time0 function. The rand0 function returns a number from 0 to RAND MAX (which is usually at least 32,767). However, we need a number from 0 to 1, You can use the % (mod) operator to convert the number to the desired range. The following statement generates a random integer from 0 to 1 int r-(rand() % 2)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Refactoring Databases Evolutionary Database Design

Authors: Scott Ambler, Pramod Sadalage

1st Edition

0321774515, 978-0321774514

More Books

Students also viewed these Databases questions