im required to move a robot 4 direction wid is generated by a random number 1 to 4. if direction is 1 the row will increase by 1, if direction is 2, row will decrease by 1, if direction is 3 column will increase by 1, if direction is 4, column will decrease by one. this is wat i have so far....
class Robot
{
private:
string name;
int targetrow;
int targetcolumn;
public:
Robot(string n, int r, int c);
void move(int direction);
void calenergy();
int getEnergy();
string getName();
};
Robot::Robot(string n,int r, int c)
{
n = name;
r = targetrow;
c = targetcolumn;
}
void Robot::move(int direction)
{
int direction; int row, column;
You forgot the 4 in direction = rand() % 4 +1;. Your constructor is assigning the parameters the value of the private variables but it should do the opposite. Also, what is the meaning of the various uses of bool operators? Were these meant to be conditions?
I would recommend to review the first chapters of the C++ tutorials before you go back to the code.
Why dont you make it simple and just do something like a coordinate system. Make it check for the random number like you did above and if it is that number it moves. I dont see the point of voids and classes if you want to make it this simple.