Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!