Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Only Part 1: Peek-a-boo is a fun game that little kids like to play. To simulate this game on the computer, write a program

C++ Only

Part 1:

Peek-a-boo is a fun game that little kids like to play. To simulate this game on the computer, write a program that will generate a random number between 1 and 4. Then, will print to the screen the animal name associated to that number. The animal names used will be:

pig when a 1 is generated

cow when a 2 is generated

chicken when a 3 is generated

horse when a 4 is generated

If your program generates a 3, the output will be:

chicken

The player will then enter a 1 if they would like to play again or anything else to exit the program.

If the player enters "1 1 1 0", the output will be: horse chicken cow

For coding simplicity, follow each output animal by a space, even the last one.

Hint: To make testing easier, seed your random number generator with 0.

-------------------------

When I run my program, it prints

> run <<< "1 1 1 0" 1 1 1 0 horse chicken cow > 

---------

Help me fix it to print: horse chicken cow , not

horse

chicken

cow

--------------------------------------

My code:

#include #include using namespace std;

int main() {

int ranNum; srand(0); int num1 = 1; cin >> num1;

while ( num1 == 1) { ranNum = rand()% 4 + 1; if ( ranNum == 1) { cout << "pig" << endl; } else if ( ranNum == 2) { cout << "cow" << endl; } else if ( ranNum == 3) { cout << "chicken" << endl; } else if (ranNum == 4) { cout << "horse" << endl; } cin >> num1; }

return 0; }

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

Step: 3

blur-text-image

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

Conceptual Database Design An Entity Relationship Approach

Authors: Carol Batini, Stefano Ceri, Shamkant B. Navathe

1st Edition

0805302441, 978-0805302448

More Books

Students also viewed these Databases questions