Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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_2

Step: 3

blur-text-image_3

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

Computer Performance Engineering 10th European Workshop Epew 2013 Venice Italy September 17 2013 Proceedings

Authors: Maria Simonetta Balsamo ,William Knottenbelt ,Andrea Marin

2013 Edition

3642407242, 978-3642407246

More Books

Students also viewed these Programming questions