Question: You can use the following code to determine which direction the robot will move at each step. srand ( time ( 0 ) ) ;

You can use the following code to determine which direction the robot will move at each step.
srand(time(0));
int direct;
direct = rand()%4+1; //random number between 1 and 4 so each is 25%//probable
//1 means North, 2 means South, 3 means East and 4 means West
1. The robot moves 25 times. At each step, how many blocks away (print this in north or south, east or west of the starting point) is the robot from the starting point?
2. You want the robot to get to a point that is 2 blocks to the east and 3 blocks to the north of the starting point. Given the same random choices for moves, change your code so that your code prints out how many steps it took to get to the destination point.
the language is c++

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!