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;)

it wasnt meant to be smily but "; )"

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

commented: agree -- changing to switch doesn't make sense :) +24

it wasnt meant to be smily but "; )"

fixed it for you, scroll down and you will see a checkbox to disable smileys in the text.

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);

commented: The OP doesn't know what he wants to do either :) +24

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.