Below is a function i'm trying to use to decide if a player has moved a checkers piece up left or up right. moveTo
holds a decimal like 5.2 and moveFrom
would hold square number 6.3 the difference would be -1.1 and is assigned to moveValue
(i'm checking it with the trace statement and it is assigning correctly).
however when it hits the ifs it's not coming out as equal and so it runs the last if statement, however if i hard code -1.1 to moveValue
it does evaluate correctly. Any ideas why it's not evaluating correctly would be a big help. I have posted the output from running the program under the code :
int legalPlayerMove(float moveTo, float moveFrom)
{
float moveValue=(moveTo-moveFrom);
cout<<"trace move value"<<moveValue<<endl;
if(moveValue==(-1.1))
cout<<"moved up left"<<endl;
if(moveValue==(-0.9))
cout<<"moved up right"<<endl;
if(moveValue!=-1.1||moveValue!=-.9)
cout<<"that is not a legal move, please renter the square number you wish to move to."<<endl;
return 0;
}
- please enter the location of the piece you want to move
- 6.3
- now please enter where you would like to move the piece
- 5.2
- trace move value-1.1
- that is not a legal move, please renter the square number you wish to move to.
- Tress any key to continue . . .