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

Use C language only (AND NOT C# or C++ or java or any other language.) Requireme

ID: 3844737 • Letter: U

Question

Use C language only (AND NOT C# or C++ or java or any other language.) Requirement: let user input a coordinate in following format (x, y) as a start point, Then continuously let user enter a set of command and update the coordinate accordinging. The command must use the following (l - for left, r - for right, d - down, u - up, s - stop). For example, if initial position is given x = 5, y =6. (5, 6) And if command key (l) is entered. Then an application will output new line call "Current location is (4, 6)" without interrupting. Then, the application will continue to prompt user for another command without interrupting "please press next command". Then, If a letter other than the 5 allowed letter (l, r, d, u, s) here is entered. The application will output message "command exception, last location is (4, 6)" and without interrupting Then, If command key (d) is pressed. The application will update the position from (4, 6) to (4, 5) and output the following message "current location is (4, 5)." without interrupting Then, If the command (r) is pressed. The application will continue to update from last location (4, 5) and output new message "current location is (5, 5)". without interrupting Then, If command key (u) The application will update the position from (5, 5) and output new message "current location is (5, 6)". without interrupting Finally, If the command (s) is pressed, the application will repeat the last position (5, 6) and output message "location is (5, 6)" application will stop.

Explanation / Answer

Program

#include<stdio.h>
int main()
{


//scanf("%d",&y);
//printf("%d ,%d",x,y);
int j=1,k=0;
char s;
while(j!=2)
{
int x,y;
if(k==0)
{

printf("Enter The Coordinates: ");
scanf("%d%d",&x,&y);
}

printf(" Enter The Command (l,r,d,u,s): ");
scanf("%s",&s);
k++;
switch(s)
{
case 'l':
y=y-1;
printf(" Current Location Is :( %d,%d )",x,y);
break;

case 'r':
y=y+1;
printf(" Current Location Is :( %d,%d )",x,y);
break;

case 'u':
x=x-1;
printf(" Current Location Is :( %d,%d )",x,y);
break;

case 'd':
x=x+1;
printf(" Current Location Is :( %d,%d )",x,y);
break;

case 's':
printf(" Location Is :( %d,%d )",x,y);
j=2;
break;

default:
printf(" Command Exception.Last Location Is :( %d,%d )",x,y);
break;
}
}
}

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