Let me start of by saying hello to ye all, since this is my first post. I took up c++ programming about a week ago, with the help of "The C++ Programming Language 3rd ed" and various tutorials and the like on the internet.. Ahh, now that that's out of the way lets go to my problem. Consider this part of my code:
Now, when I run the program it does what it is supposed to, but also what is in the "else part" (You cannot do that!)Code:int movement() { cout << "\t\tTurn: " << turn+1 << endl << endl; cout << "You are in zone "<< cordX << "-" << cordY << "-" << cordZ << endl; int a=0; while(a==0) { mov=getch(); if(mov=='w') //north { a=a+1; cordX=cordX+1; turn=turn+1; } if(mov=='s') //south { a=a+1; cordX=cordX-1; turn=turn+1; } if(mov=='d') //east { a=a+1; cordY=cordY+1; turn=turn+1; } if(mov=='a') //west { a=a+1; cordY=cordY-1; turn=turn+1; } if(mov=='z') //in { a=a+1; cordZ=cordZ+1; turn=turn+1; } if(mov=='x') //out { a=a+1; cordZ=cordZ-1; turn=turn+1; } else //anything else is an error { cout << "You cannot do that!" << endl; } } return 0; }
I'm sure it's just some trivial mistake, but I can't see it..