How do I get my Latex pseudo code displayed appropriately

I wrote this code using latex, however, whenever I run it I and =0 at the end. Please how do I get to stop displaying '=0'.

Below is my Latex pseudo code:

\begin{algorithm}
\caption{Approximate Point in Triangulation Algorithm}

\begin{algorithmic}

\State S represents the set of anchors seen/reached by the free node.
\State $N_i$ represents the set of anchors seen/reached by each
\State anchor \in S. \newline
\setlength{\parindent}{5ex} \State For \mid$S$\mid  number of anchors \{}
\State reachNodes = S\cap $N_i$)
\State { \}
\State sort reachNodes in descending order
\State select the three highest reachNodes
\State /* Centre of Gravity(COG) calculation */
\State Estimated Position $=$ COG of three highest reachNodes; \newline
\end{algorithmic}
\end{algorithm}


this is what is displayed:

Your code contains several LaTeX errors. If you skip over them then the output will be garbled.

• Typeset mathematics in math mode, and take care that the math mode is terminated again.

• Indentation is one of the things that the algorithms environment takes care of; just use the commands provided, \For in this case.

• You don't need \newlines. The line wraps automatically. If you don't want that the algorithm occupies the whole width, put the algorithmic environment into a minipage: \begin{minipage}{7cm}\begin{algorithmic}...\end{algorithmic}\end{minipage}

\documentclass{article}
\usepackage{algpseudocode,algorithm}
\begin{document}
\begin{algorithm}
\caption{Approximate Point in Triangulation Algorithm}
\begin{algorithmic}
\State $S$ represents the set of anchors seen/reached by the free node.
\State $N_i$ represents the set of anchors seen/reached by each anchor $i{}\in S$.
\For{each anchor $i\in S$}
\State $\mathit{reachNodes} = S\cap N_i$
\EndFor
\State sort $\mathit{reachNodes}$ in descending order
\State select the three highest nodes in $\mathit{reachNodes}$
\State /* Centre of Gravity (COG) calculation */
\State Estimated Position $=$ COG of three highest $\mathit{reachNodes}$;
\end{algorithmic}
\end{algorithm}
\end{document}

• Thanks, however, I ran it and I still got an =0 – Kola Jan 3 '17 at 10:29
• @Kola Did you run exactly my code, with latex or pdflatex? My guess is no. Check the packages that you load. Remove the package algorithmic, it is not necessary, but in fact generates =0 when used together with algorithmicx (loaded implicitly by algpseudocode). – gernot Jan 3 '17 at 10:39
• below are my packages: \usepackage{graphicx} \usepackage{blindtext} \usepackage[table]{xcolor} \usepackage{algpseudocode} \usepackage{algorithm} \usepackage{cite} \usepackage{graphicx} \usepackage[cmex10]{amsmath} \usepackage[tight,footnotesize]{subfigure} \hyphenation{op-tical net-works semi-conduc-tor} \usepackage[none]{hyphenat} \usepackage[justification=centering]{caption} \usepackage[labelsep=space]{caption} – Kola Jan 3 '17 at 10:50
• @Kola Nothing wrong with these packages: when I paste this preamble into the document above (instead of the \usepackage command there), the result looks fine, no =0. Please compile the document above (maybe with your preamble) and verify that there is also no problem for you. This then means that the problem is somewhere else in your document. If your output is different, then you proabably use an old version of some style file. Unrelated: Load caption only once, using \usepackage[justification=centering,labelsep=space]{caption}. – gernot Jan 3 '17 at 10:56
• @Kola If you are stuck, append the code of your document (reduced as much as you can) to your post, starting with \documentclass and ending with \end{document}. Before doing so, please make sure that the code as posted still shows the problem. – gernot Jan 3 '17 at 11:13