Question
CSCI-1151 Introduction to Programming Exercise: Godzilla vs. New Mexico In this exercise, we're going to practice random numbers andloops by simulating Godzilla invading New Mexico.
CSCI-1151
Introduction to Programming
Exercise: Godzilla vs. New Mexico
In this exercise, we're going to practice random numbers andloops by simulating Godzilla invading New Mexico.
Here's a few important facts about Godzilla:
- When Godzilla enters New Mexico, Godzilla eats 1 human.
- Each human's stomach contains either green chile or redchile.
- There is a 75% chance of green chile in a human's stomach and a25% chance of red.
- If Godzilla eats a human who just ate green chile, Godzillaeats another human.
- If Godzilla eats a human who just ate red chile, Godzilladies.
We're going to write a program that simulates Godzilla enteringNew Mexico, then prints the number of humans Godzilla ate beforedying.
- Write a function with the following prototype:
int EatNextHuman();
This function will simulate eating a human. When called, thisfunction should return 1 75% of the time to indicate there wasgreen chile in the human, and return 0 25% of the time to indicatered chile.
In your main,
- Create a variable to track how many humans godzilla has eaten,initialize it to 0.
- Write a loop to simulate the situation. You loop should:
- Call EatNextHuman()
- Increase humans eaten by 1
- If EatNextHuman() returned 1, keep looping (eat anotherhuman)
- After the loop, print the number of humans eaten./
Bonus
Try making your program run the simulation 10 times, then printthe average number of humans eaten (10 pts).
Try changing your program so Godzilla can eat 3 red-chile humansbefore dying (10 pts).
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started