Hello daniweb peeps, been learning c++ from a beginners book for the past week or two but have got myself a bit confused, follows is the code that compiles but isn't doing what i want it to (Im hoping the fault is obvious!)
#include <iostream>
using namespace std;
int main(){
int toX = 100, toY = 200, currentX = 0, currentY = 0;
do{
if(currentX < toX)
{ currentX++; }
else
{ currentX--; }
if(currentY < toY)
{ currentY++; }
else
{ currentY--; }
cout << "Scout curr location: " << currentX << "," << currentY << endl;
} while ( (toX != currentX) && (toY != currentY) );
cout << "Unit arrived at " << toX << "," << toY << endl;
return 0;
}
My issue is, the while statement is obviously becoming true and ending my loop too early, it will say "scout arrived at 100,200" - it will of jumped, it seems to be that the while statement is not looking at the && section and is just using part of it..
Remember to word your replies if there are any in easy terms,
thanks for any input you may have!
cheers
Paul
(i did use search etc but nothing of any relevence to my basic question!)