Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Function Issue: I am having issues with my counter function. Basically it is to pick 3 random numbers b/w 0 and 1. If the first

Function Issue:

I am having issues with my counter function. Basically it is to pick 3 random numbers b/w 0 and 1.

If the first number is 0, the rabbit doesn't move.

if the second number is 0, the rabbit moves left or right

if the third number is 0, the rabbit moves up or down.

#include #include // For time() #include // For srand() and rand() #include // std::flush #include #include #include #include #include

using namespace std;

//generates random numbers 0 or 1 int coinToss() { return rand() % 2; } counter() { int x=1; int counter1; while (x!=0){

for (int counter1 = 1; counter1 <=3 ; counter1++) { int x= (rand()%2); int coinToss(x);

cout << "x equals " << x << " "; cout << "counter is " << counter1 << endl; } //if (x==0) //{ //return counter1; // break; // }} if (counter1 == 1) { cout << "Rabbit doesn't move"; } else if (counter1 ==2) { cout << "Rabbit moves left or right" << endl; int x= (rand()%2); int coinToss(x);

if (x==0) { cout << "Rabbit moves left"; } else { cout << "Rabbit moves right"; } } else { cout << "Rabbit moves up or down"<< endl; int x= (rand()%2); int coinToss(x); if (x==0) { cout << "Rabbit moves up"; } else { cout << "Rabbit moves down"; } }}

};

int main() { srand(time(NULL));

counter();

};

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

Online Systems For Physicians And Medical Professionals How To Use And Access Databases

Authors: Harley Bjelland

1st Edition

1878487442, 9781878487445

More Books

Students also viewed these Databases questions

Question

5. Understand how cultural values influence conflict behavior.

Answered: 1 week ago