1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
#include <stdio.h>
#include <conio.h>
#include "again.h"
void main()
{
int x,y;
char cmd;
printCommand();
cmd = getch();
switch(cmd){
case 'a'
:initialize(&x,&y);
printf("\nx=%d,y=%d",x,y);
break;
case 'b'
:printLocation(x,y);
break;
case 'c'
:move(&x,&y);
printf("\nThe current location is x=%d,y=%d",x,y);
break;
exit();
printf("GOODBYE:");
}
}
char printCommand(void){
printf("Enter the command you want to execute\nA.]Origin\nB.]Location\nC.]MOVE\nD.]EXIT\n");
return 0;
}
void initialize(int *x,int *y){
*x=0;
*y=0;
}
void printLocation (int x, int y){
printf("\nthe current location is %d,%d",&x,&y);
}
void move(int *x, int *y){
int direction,points;
printf("\nEnter the direction you want to move: ");
scanf("%d",&direction);
printf("\nhow many points you want to move?:");
scanf("%d",&points);
if(direction==1)
*x+=points;
else if(direction==2)
*y+=points;
else if(direction==3)
*x-=points;
else if(direction==4)
*y-=points;
else
printf("\nINVALID DIRECTION!!!:");
}
void exit(void)
{
return 0;
}
|