Displacement from origin after N moves of given distances in specified directions

  #include using namespace std;  void finalPosition(char a[], int b[],                   int M){                int n = 0, s = 0, e = 0, w = 0;              char p = ‘N’;          for (int i = 0; i < M; i++) {                          if (p == 'N') {              if (a[i] == 'U') {                p = 'N';                n = n + b[i];            }            else if (a[i] == 'D') {                p = 'S';                s = s + b[i];            }            else if (a[i] == 'R') {                p = 'E';                e = e + b[i];            }            else if (a[i] == 'L') {                p = 'W';                w = w + b[i];            }        }                          else if (p == 'S') {            if (a[i] == 'U') {                p = 'S';                s = s + b[i];            }            else if (a[i] == 'D') {                p = 'N';                n = n + b[i];            }            else if (a[i] == 'R') {                p = 'W';                w = w + b[i];            }            else if (a[i] == 'L') {                p = 'E';                e = e + b[i];            }        }                          else if (p == 'E') {            if (a[i] == 'U') {                p = 'E';                e = e + b[i];            }            else if (a[i] == 'D') {                p = 'W';                w = w + b[i];            }            else if (a[i] == 'R') {                p = 'S';                s = s + b[i];            }            else if (a[i] == 'L') {                p = 'N';                n = n + b[i];            }        }                          else if (p == 'W') {            if (a[i] == 'U') {                p = 'W';                w = w + b[i];            }            else if (a[i] == 'D') {                p = 'E';                e = e + b[i];            }            else if (a[i] == 'R') {                p = 'N';                n = n + b[i];            }            else if (a[i] == 'L') {                p = 'S';                s = s + b[i];            }        }    }              int ver_disp = n - s;              int hor_disp = e - w;          int displacement = floor(        sqrt((ver_disp * ver_disp)             + (hor_disp * hor_disp)));              cout