I need a C++ program with the following instructions: Write a program about the
ID: 3887233 • Letter: I
Question
I need a C++ program with the following instructions:
Write a program about the race between the rabbit and the turtle.
Use random numbers to develop a simulation. Begin the race at square 1 of 70.
Each square represents a position along the course of the race with the end line
at square 70. The clock ticks once per second adjusting the position of both
each time.
Begin the race by printing: Bang !!!! And they're off!!!!
Start each animal at position 1.
If animal slips left before square 1, move back to square 1.
For each tick of the clock (repetition of the loop), print a 70-position line
showing the letter T for turtle and R for rabbit. If both land in same square,
the turtle bites the rabbit and program prints OUCH!!! beginning at that position.
All print positions other than the T, R or OUCH!!! should be blank.
After each line, determine whether either animal has reached or passed square 70.
If so, print name of winner, terminate. If turtle wins print: Turtle Wins!!! Yay!!!
If Rabbit wins: Rabit wins. Yuch. If neither, perform loop again to simulate the next
tick of the clock.
Explanation / Answer
#include <iostream>
#include <stdio.h>
#include <time.h>
const int FINISH = 70;
int main()
{
int R = 0, T = 0;
std::cout<<" Here The Race begins between Hare and the Turtlee";
std::cout<<" Bang!!! And They Are OFF!!!!!!";
while(T < FINISH && R < FINISH)
{
srand(time(NULL));
int race = rand() % 10 + 1;
if(race >= 8)
T += 1;
else if(race >= 6)
T += -6;
else if(race >= 1)
T += 3;
if(race >= 8)
R += 1;
else if(race >= 6)
R = R;
else if(race >= 4)
R += 9;
else if(race == 3)
R -= 12;
else if(race >= 1)
R -= 2;
else if(R == T)
{
for(int j = 0; j < R - 1; j++)
{
std::cout<<" ";
}
std::cout<<" Ouch!!!";
}
for(race = 0; race<= 70; race++)
{
if(race == R)
{
std::cout<<" Rabbit!!!";
}
else if(race == T)
{
std::cout<<" Turtle!!!";
}
else
std::cout<<" - " <<" ";
}
}
if(T >= 70 && R >= 70)
{
std::cout<<" It's a tie, It's a tie!!!!!!";
}
if(T >= 70)
{
std::cout<<" Rabbit Wins!!!";
}
if(R >= 70)
{
std::cout<<" Turtle Wins!!! YAY!!!";
}
return 0;
}
OUTPUT
Here The Race begins between Hare and the Turtlee
Bang!!! And They Are OFF!!!!!! -
-
-
Turtle!!! -
-
-
-
-
-
Turtle!!! -
-
-
Turtle!!! -
-
-
Turtle!!! -
-
-
-
Turtle!!! -
-
-
Turtle!!! -
-
-
-
-
Turtle!!! -
-
-
-
Turtle!!! -
-
-
Turtle!!! -
-
-
-
Turtle!!! -
-
-
-
Turtle!!! -
-
Turtle!!! -
-
-
-
-
-
Turtle!!! -
-
-
-
Turtle!!! -
-
-
-
Turtle!!! -
-
-
Turtle!!! -
-
-
Turtle!!! -
-
-
-
Turtle!!! -
-
-
-
Turtle!!! -
-
-
-
Turtle!!! -
-
-
-
Turtle!!! -
-
-
-
Turtle!!! -
-
-
-
-
-
Turtle!!! -
-
-
-
Rabbit Wins!!!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.