Hi ive been making my C++ program for several hours and I cant seem to make it work.
heres the code
I have a one or two problem, the main problem is that the fuction printLocation it doesnt return the correct value of x and y instead it gave me a very huge amount, the other problem is how can i terminate a program using a fuction. thanks in advance.Code:#include <stdio.h> #include <conio.h> #include "again.h" int main() { int x=0,y=0; char cmd; do{ 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; } } while(cmd!='d'); printf("Goodbye:"); exit(); } 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) { }




Reply With Quote