Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I'm pretty mediocre at programming, so help with writing this C Program would be great!! Thanks!! In this problem, youll recreate one of the truly

I'm pretty mediocre at programming, so help with writing this C Program would be great!! Thanks!!

In this problem, youll recreate one of the truly great moments of our very own childhood tale, namely the classic race of the tortoise and the hare. Youll use random number generation to develop a simulation of this memorable event.

Our contenders begin the race at square 1 of 70 squares. Each square represents a possible position along the race course. The finish line is at square 70.

The first contender to reach or pass square 70 is rewarded with a pail of fresh carrots and lettuce.

The course weaves its way up the side of a slippery mountain, so occasionally the contenders lose ground.

Theres a clock that ticks once per second. With each tick of the clock, your program should adjust the position of the animals according to the rules as follows:

Animal Move type Percentage of the time Actual move

Tortoise: Fast plod 50% 3 squares to the right

Slip 20% 6 squares to the left

Slow plod 30% 1 square to the right

Hare: Sleep 20% No move at all

Big hop 20% 9 squares to the right

Big slip 10% 12 squares to the left

Small hop 30% 1 square to the right

Small slip 20% 2 squares to the left

Use variables to keep track of the positions of the animals (i.e., position numbers are 1 70). Start each animal at position 1 (i.e., the starting gate). If an animal slips left before square 1, move the animal back to square 1. Generate the percentages in the preceding table by producing a random integer, i, in the range 1 i 10. For the tortoise, perform a fast plod when 1 i 5, a slip when 6 i 7, or a slow plod when 8 i 10. Use a similar technique to move the hare.

Begin the race by printing BANG !!!!! AND THEY'RE OFF !!!!!

Then, for each tick of the clock (i.e., each repetition of a loop), print a 70-position line showing the letter T in the position of the tortoise and the letter H in the position of the hare. Occasionally, the contenders will land on the same square. In this case, the tortoise bites the hare and your program should print OUCH!!! beginning at that position. All print positions other than the T, the H, or the OUCH!!! (in case of a tie) should be blank as shown in Figure 1 and 2 below. You can print S as the start position and F as the finish position.

After each line is printed, test whether either animal has reached or passed square 70. If so, then print the winner and terminate the simulation. If the tortoise wins, print TORTOISE WINS!!! If the hare wins, print HARE WINS!!! As shown in Figure 3.

If both animals win on the same tick of the clock, print IT'S A TIE!!!

If neither animal wins, perform the loop again to simulate the next tick of the clock.

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

Handbook Of Relational Database Design

Authors: Candace C. Fleming, Barbara Von Halle

1st Edition

0201114348, 978-0201114348

More Books

Students also viewed these Databases questions

Question

What are the stages of project management? Write it in items.

Answered: 1 week ago

Question

3. What are potential solutions?

Answered: 1 week ago