Apologies for it being very long horizintally
- but you dont need any of the code
on the far right anyway
right. I have
and its not doing as its told.Code:scanf("%c",&look);
Under it follow a whole forray of if statements
the last of which was you entered an invlaid character
(N, S, W, E are valids, the rest non valid) The only problem is
when i run the code it doesnt actually ask for an input for look
, and then continues as if an invalid character has been entered
The whole function is below and is almost an exact duplicate of another i have written that works fine.
i realise its ugly, but its all structures in structures....Code:void inspect(object *p1, rover *myRover, location **map) { int mapsizex, mapsizey; char look; mapsizex=myRover->mapsizex; mapsizey=myRover->mapsizey; map[myRover->Current_x][myRover->Current_y-1].ObjId=12; printf("\n\nIn which direction would you like to look??\nPlease enter N,E,S, or W\n\n"); scanf("%c",&look); if(look=='N') { if( ((myRover->Current_x&&myRover->Current_y)>=0) && ((myRover->Current_x<=(mapsizex-1))&&(myRover->Current_y<=(mapsizey-1)))) { if((map[myRover->Current_x][myRover->Current_y+1].ObjId!=12) && (map[myRover->Current_x][myRover->Current_y+1].ObjId!=9)) { printf("\nHere there is a %s, %s\n",p1->objname[map[myRover->Current_x+1][myRover->Current_y].ObjId], p1->objtype[map[myRover->Current_x+1][myRover->Current_y].ObjId]); (myRover->power)--; } else printf("\nSorry, You can not move to that square, it is occupied by:\n%s, \n%s\n\n", p1->objname[map[myRover->Current_x][myRover->Current_y].ObjId], p1->objdesc[map[myRover->Current_x][myRover->Current_y+1].ObjId]); } else printf("\nSorry you are at the edge of the map\n"); } else if(look=='S') { if( ((myRover->Current_x&&myRover->Current_y)>=0) && ((myRover->Current_y<=(mapsizey)))) { if((map[myRover->Current_x][myRover->Current_y-1].ObjId!=12) && (map[myRover->Current_x][myRover->Current_y-1].ObjId!=9)) { printf("\nHere there is a %s, %s\n",p1->objname[map[myRover->Current_x-1][myRover->Current_y].ObjId], p1->objtype[map[myRover->Current_x-1][myRover->Current_y].ObjId]); (myRover->power)--; } else printf("\nSorry, You can not move to that square, it is occupied by:\n%s, \n%s\n\n", p1->objname[map[myRover->Current_x][myRover->Current_y-1].ObjId], p1->objdesc[map[myRover->Current_x][myRover->Current_y-1].ObjId]); } else printf("\nSorry you are at the edge of the map\n"); } else if(look=='E') { if( ((myRover->Current_x&&myRover->Current_y)>=0) && ((myRover->Current_x<=(mapsizex-1))&&(myRover->Current_y<=(mapsizey-1)))) { if((map[myRover->Current_x+1][myRover->Current_y].ObjId!=12) && (map[myRover->Current_x+1][myRover->Current_y].ObjId!=9)) { printf("\nHere there is a %s, %s\n",p1->objname[map[myRover->Current_x][myRover->Current_y+1].ObjId], p1->objtype[map[myRover->Current_x][myRover->Current_y+1].ObjId]); (myRover->power)--; } else printf("\nSorry, You can not move to that square, it is occupied by:\n%s, \n%s\n\n", p1->objname[map[myRover->Current_x+1][myRover->Current_y].ObjId], p1->objdesc[map[myRover->Current_x+1][myRover->Current_y].ObjId]); } else printf("\nSorry you are at the edge of the map\n"); } else if(look=='W') { if( ((myRover->Current_x&&myRover->Current_y)>=0) && ((myRover->Current_x<=(mapsizex)))) { if((map[myRover->Current_x-1][myRover->Current_y].ObjId!=12) && (map[myRover->Current_x-1][myRover->Current_y].ObjId!=9)) { printf("\nHere there is a %s, %s\n",p1->objname[map[myRover->Current_x-1][myRover->Current_y].ObjId], p1->objtype[map[myRover->Current_x-1][myRover->Current_y].ObjId]); (myRover->power)--; } else printf("\nSorry, You can not move to that square, it is occupied by:\n%s,\n%s\n\n", p1->objname[map[myRover->Current_x-1][myRover->Current_y].ObjId], p1->objdesc[map[myRover->Current_x-1][myRover->Current_y].ObjId]); } else printf("\nSorry you are at the edge of the map\n"); } else { printf("\nThe direction must be given as a capital letter, N,S,E or W\nyou entered: %c \n\n",look); } printf("%d %d\n", myRover->Current_x, myRover->Current_y); system("pause"); }
but its not even going into the primary five if statements,
just jumping straight to the fifth and saying invalid input from the user.
Any ideas?
Cheers,
Mitch



LinkBack URL
About LinkBacks



