Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

4) PE 05b_04 (Roll Two Dice) Write a function that generates a random number sim

ID: 3905961 • Letter: 4

Question

4) PE 05b_04 (Roll Two Dice) Write a function that generates a random number simulating the roll of two six-sided dice. The function should take no arguments and return a random number simulating a single roll of two six-sided dice. Test the function in a simple loop and print at least 25 iterations to the screen. 5) PE 05b 05 (Coin Toss) Write a function that simulates flipping a coin. The function should take no arguments and return a 0 or 1. Test the function using a simple loop in a program and print to the screen "heajis" or "tails."

Explanation / Answer

#include #include #include int flip() { return rand() % 2; } int main() { srand(time(NULL)); int i; for(i = 0; i < 10; ++i) { if(flip() == 0) { printf("heads "); } else { printf("tails "); } } return 0; }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote