I have written the code and it only prints N and E directions.
Shortest Path Reduced String Problem
In your code at line 31 you have
for(int i=0; i<x; i++){
if(x>0){
cout<<βEβ;
}
else if(x<0){
cout<<βWβ;
}
}
take a look at the condition of for loop ,the loop will run if i<x and you initialized i with 0 ,so when x <0 then i>x and loop wonβt execute thus not printing W and similar argument is for case of not printing S
I have corrected your code : https://ide.codingblocks.com/s/182487
Thanks a lot abhijeet!
In case of any doubt feel free to ask me 
If you got the solution mark your doubt as resolved
What is the logic behind x++ after cout<<βWβ; and vice versa?
let say if x=-3 that means that we are 3 units to the left of origin so we have to print W three times
while(x!=0){
cout<<W;
x++;
}
ensures that loop runs 3 times and x will take values of 3 2 1 0(loop breaks)