can any body convert this to switch statement
thankxxxx..

public char CheckDir(int row, int col, int selectedX, int selectedY)
        {
if (row == selectedX)
            {
                if (col - selectedY == -2) { return 'd'; }                //DOWNWARDS
                else if (selectedY + 2 == col) { return 'u'; }     //UPWARDS
            }

            else if (col == selectedY)
            {
                if (row - selectedX == -2) { return 'l'; }                //LEFTBOUND
                else if (selectedX + 2 == row) { return 'r'; }     //RIGHTBOUND
            }

i did this but its not working

public char CheckDir(int row, int col, int selectedX, int selectedY)
        {
            switch (dir)
            {
                case 'd': row == selectedX;
                    break;
                case 'u': selectedY + 2 == col;
                    break;
                case 'l': row - selectedX = 2;
                    break;
                case 'r': selectedX + 2 == row;
                    break;
                    default: return 'o';
            }

Why do you want to convert that code to switch? It's not a good candidate for that.

line 3: where is dir declared ?

line 5: The == operator is a boolean operator, not an assignment operator. So, as writtin, that line does nothing. If you intend to set row to the value of selectX then you have to use the assignment operator =, not ==.

the dir is decared global...
i changed the == to = but still complains about
this part (row - selectedX = 2;)

row - selectedX = 2;

first off,you're lacking an equal sign if you are trying to compare values

that part is having an error because you used the assignment(=) operator
assignments should be like this:

variable_being_assigned = value_to_be_assigned

secondly

i don't quite get your problem

with your if statements,the u,d,l,r are return values

in switch case statements,
when you say case 'u',it means that char 'u' is the input

Comments
agree -- changing to switch doesn't make sense :)

Since I don't know what the function is supposed to do, I cannot offer much advise. However, if you plan to change the values of the parameters passed into the function, you need to pass the parameters by reference, instead of by value. I.e.
public char CheckDir(int & row, int & col, int & selectedX, int & selectedY);

Comments
The OP doesn't know what he wants to do either :)

thanx for your help the operator was wrong and you are right the character in switch means an input... ill use the if statment...

thankx.

This article has been dead for over six months. Start a new discussion instead.