Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program to determine the location of a robot as it moves through a maze^

ID: 3827496 • Letter: W

Question

Write a program to determine the location of a robot as it moves through a maze^1. The robot location controller will receive a series of commands from the user. The program should prompt the user to enter the starting x and y coordinates for the robot. Then the program should prompt the user for commands until a "stop (s)" command is entered. If an invalid command is entered, the program should indicate that it is an invalid input and request another command. After each command the program should display the current position of the robot. At the end, the program should display the final position of the robot. Commands include: I - go left one space r - go right one space d - go down one space u -go up one space s - stop while ((ch = get char ()) ! = ' ' && ch ! = EOF); Sample output shown below (yours can be formatting differently). Test with different input values. Make sure to fully test your code and submit any necessary screen shots.

Explanation / Answer

PROGRAM:

#include <stdio.h>

int main()

{

// integer varibal x,y

int x=0;

int y=0;

  

printf("program to control a robot");

printf(" please enter cordiates of start position");

printf(" X:");

//reading the values of x

scanf("%d",&x);

printf(" Y:");

   //reading the values of y

scanf("%d",&y);

printf(" current possion of robot:(%d ,%d)",x,y);

printf(" command to control robot include:");

printf("r-right l-left u-up d-down s-stop");

printf(" Eneter the first command :");

char ch;

//getting the user input value

ch=getchar();

//infinite loop for getting the user choice

while(1)

{

// getting the charater for movement

ch=getchar();

switch (ch)

{

case 'r':

//incrementing the x coordinate by 1 for right movement

x=x+1;

printf(" current possion of robot:(%d ,%d)",x,y);

break;

case 'l':

//decrementing the x coordinate by 1 for left movement

x=x-1;

printf(" current possion of robot:(%d ,%d)",x,y);

break;

case 'u':

//incrementing the y coordinate by 1 for up movement

y=y+1;

printf(" current possion of robot:(%d ,%d)",x,y);

break;

case 'd':

////decrementing the y coordinate by 1 for down movement

y=y-1;

printf(" current possion of robot:(%d ,%d)",x,y);

break;

case 's':

//stopping the movements and goto the label EndWhile

printf(" Final possion of robot:(%d ,%d)",x,y);

   goto EndWhile;

break;

default:

printf(" enter valid input :");

break;

}

printf(" Eneter the next command :");

ch=getchar();

}

//EndWhile label

EndWhile:

  

return 0;

}

OUTPUT:

program to control a robot

please enter cordiates of start position

X:4

Y:7

current possion of robot:(4 ,7)

command to control robot include:r-right l-left u-up d-down s-stop

Eneter the first command :l

current possion of robot:(3 ,7)

Eneter the next command :r

current possion of robot:(4 ,7)

Eneter the next command :u

current possion of robot:(4 ,8)

Eneter the next command :d

current possion of robot:(4 ,7)

Eneter the next command :o

enter valid input :

Eneter the next command :l

current possion of robot:(3 ,7)

Eneter the next command :r

current possion of robot:(4 ,7)

Eneter the next command :u

current possion of robot:(4 ,8)

Eneter the next command :l

current possion of robot:(3 ,8)

Eneter the next command :s

Final possion of robot:(3 ,8)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote