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.

  1. 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,

  1. Create a variable to track how many humans godzilla has eaten,initialize it to 0.

  1. Write a loop to simulate the situation. You loop should:
    1. Call EatNextHuman()
    2. Increase humans eaten by 1
    3. If EatNextHuman() returned 1, keep looping (eat anotherhuman)

  1. 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

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 Programming Questions!