Question: flips. - Work with built-in C functions. lated SLO: - Develop properly structured multifile programs with automatic compilation. tructions - Create a program named LastnameFirstname08.


flips. - Work with built-in C functions. lated SLO: - Develop properly structured multifile programs with automatic compilation. tructions - Create a program named LastnameFirstname08. c, that does the following: 1. Setup your program to use the custom getdouble() function. Ensure the necessary files in the directory and include in the program. 2. Create a makefile named makefile that will automatically compile, link, and create an executable for this assignment. - You may use makefile-double as a template makefile, but be sure it is named makefile - Do NOT submit a makefile named makefile-double or any other name. 3. Setup your program to generate a random number. A. Include the necessary header files at the top of your program. There are 2 includes that are associated with random numbers. In total, you should have 4 includes after setting up your program to generate random numbers. B. Seed the random generator using UNIX time. 4. Declare and initialize two variables that will represent the outcome of each flip, heads or tails. 5. Output a message telling the user what this program does and ask how many times they want to flip the coin. 6. Use the custom getdouble() function to get the number and store it in an integer variable. Typecast the return value when assigning to the variable. For example: int numFlips = (int) getdouble (); 7. Perform an error check on the input. If the number is less than 1 , output a message to the user to enter an integer 1 or more, and the program should end. 8. If the number is 1 or more, proceed with simulating a coin flip. Generate a random integer to represent heads or tails. For example, 0 can mean heads and 1 can mean tails. Determine if the flip was heads or tails and increment the corresponding variable. Use a loop to repeat this process for as many times the user wanted to flip the coin. 9. After all flips have occured, output a message showing how many flips were heads and how many were tails. 10. Additionally, print a percentage breakdown of heads and tails. - Display the percentages to 2 decimal places. - To print a single percent sign using printf, use the format specifier \% - Be careful of integer division. You'll likely be using all int variables up to this point so when you calculate the percentage, you'll likely end up with an integer. To remedy this issue, multiply by 100.0 instead of 100, this will force floating-point arithmetic. For example: double percentHeads =100.0 numHeads / (numHeads + numTails); 11. Double-check your output to ensure that the program is consistenly generating different numbers. In the example output, I used the number 10000 multiple times, but notice that each output is different. If you are constantly getting the same output using the same number, it means you did not seed the random function at the beginning of the program. 12. Be sure to have a program description at the top and in-line comments. 13. Code adheres to the coding standard. 14. Be sure to have read through the assignment policy for this class. mple Output %./program Coin Flip Simulator How many times do you want to flip the coin? 10 Number of heads: 7 Number of tails: 3 Percentage of heads: 70.00% Percentage of tails: 30.00% %./program Coin Flip Simulator How many times do you want to flip the coin? 10000 Number of heads: 5088 Number of tails: 4912 Percentage of heads: 50.88% Percentage of tails: 49.12% %./program Coin Flip simulator How many times do you want to flip the coin? 10000 Number of heads: 5054 Number of tails: 4946 Percentage of heads: 50.54% Percentage of tails: 49.46% %./program Coin Flip simulator How many times do you want to flip the coin? 10000 Number of heads: 5071 Number of tails: 4929 Percentage of heads: 50.71% Percentage of tails: 49.29%
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
