need help urgently

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....

#include "stdafx.h"
#include <iostream>
#include <string>
#include <ctime>
#include <cmath>
using namespace std;

const int MAXROW = 10;
const int MAXCOLUMN = 10;

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;

direction = 0; direction <5;

srand(time(NULL));

direction = rand()% +1;

cout<< direction << endl;

if (direction = 1)
{
row =0; row < 11; row++;

if (direction = 2)
{
row = 0; row <11;row--;
if (direction = 3)
{
column = 0; column <11; column++;
if(direction = 4)
{
column = 0;column <11; column--;
}
}
}
}



}
what is wrong and how do i test if its working?
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.
yes.. they are meant to be conditions.. is there another way i shud go abt doing it?
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.
Topic archived. No new replies allowed.