user8761: I have 5 LDR and Arduino Mega. I connect them and get light level.
void loop() {
// print the analog output in milli volts
int w=analogRead(west);
Serial.print("west = ");

Serial.print(w);
Serial.println(" mv");

int e=analogRead(east);
Serial.print("east = ");

Serial.print(e);
Serial.println(" mv");

int n=analogRead(north);
Serial.print("north = ");

Serial.print(n);
Serial.println(" mv");

int s=analogRead(south);
Serial.print("south = ");

Serial.print(s);
Serial.println(" mv");

int c=analogRead(control);
Serial.print("control = ");

Serial.print(c);
Serial.println(" mv");

delay(1000);

if(e > w)
Serial.println("west");

else if(e < w)
Serial.println("east");

else if(s > n)
Serial.println("south");

else(s < n);
Serial.println("north");

Serial.println("\n");
}

This is my loop and I always see east-north. When west is bigger than east I also see east. What 

user10794: Here:
else(s < n);
-----------^

That is wrong. See Arduino programming traps, tips and style guide.

Trap #13: Don't put a semicolon at the end of every line
Semicolons end statements. However if, for and while are compound statements, so they should not have a semicolon after them like this:
Wrong! ...
  if (temperature > 40);    // <----- this semicolon is incorrect!
    {
    digitalWrite (furnaceControl, LOW);
    digitalWrite (warningLight, HIGH);
    }

  for (int i = 0; i < 10; i++);   // <----- this semicolon is incorrect!
    digitalWrite (i, HIGH);

The semicolons above (as indicated) terminate the if and for so they don't do anything useful. The lines following them are just unconditional blocks of code which are always executed, once.
Correct:
  if (temperature > 40)
    {
    digitalWrite (furnaceControl, LOW);
    digitalWrite (warningLight, HIGH);
    }

  for (int i = 0; i < 10; i++)
    digitalWrite (i, HIGH);


user3917: Nick Gammon correctly points out a problem due to an extra semicolon, but you should also note what the construct else(s < n) is doing.  When the if condition that this else gives an alternative to is false, the statement   (s < n) gets executed.  That statement is an expression statement, and its value is the evaluation of s<n, either true or false.  
If the semicolon after (s < n) weren't there, you'd get a compile error because (s < n) serial.println("north") is not a valid statement.  You may have meant to say else if(s < n) instead of else(s < n).
Note, in the sequence
if (e > w)
   Serial.println("west");
else if (e < w)
   Serial.println("east");
else if (s > n)
   ...

that last else typically is reached only rarely, because the only condition to get to it is e and w being equal.  Due to sensor noise and signal processing noise, the chance of e and w being equal is probably at most a few percent.
If your north/south test sequence is supposed to be independent of your east/west test sequence, leave out the second if and second else .  That is, instead say:
if (e > w)
   Serial.println("west");
else
   Serial.println("east");
if (s > n)
   ...


8761: <p>I have 5 LDR and Arduino Mega. I connect them and get light level.</p>

<pre><code>void loop() {
// print the analog output in milli volts
int w=analogRead(west);
Serial.print("west = ");

Serial.print(w);
Serial.println(" mv");

int e=analogRead(east);
Serial.print("east = ");

Serial.print(e);
Serial.println(" mv");

int n=analogRead(north);
Serial.print("north = ");

Serial.print(n);
Serial.println(" mv");

int s=analogRead(south);
Serial.print("south = ");

Serial.print(s);
Serial.println(" mv");

int c=analogRead(control);
Serial.print("control = ");

Serial.print(c);
Serial.println(" mv");

delay(1000);

if(e &gt; w)
Serial.println("west");

else if(e &lt; w)
Serial.println("east");

else if(s &gt; n)
Serial.println("south");

else(s &lt; n);
Serial.println("north");

Serial.println("\n");
}
</code></pre>

<p>This is my loop and I always see east-north. When west is bigger than east I also see east. What </p>
 10794: 

<p>Here:</p>

<pre class="lang-C++ prettyprint-override"><code>else(s &lt; n);
-----------^
</code></pre>

<p>That is wrong. See <a href="http://www.gammon.com.au/tips#trap13" rel="nofollow">Arduino programming traps, tips and style guide</a>.</p>

<hr>

<h2>Trap #13: Don't put a semicolon at the end of every line</h2>

<p>Semicolons end statements. However <code>if</code>, <code>for</code> and <code>while</code> are <em>compound</em> statements, so they should <em>not</em> have a semicolon after them like this:</p>

<p><strong>Wrong! ...</strong></p>

<pre class="lang-C++ prettyprint-override"><code>  if (temperature &gt; 40);    // &lt;----- this semicolon is incorrect!
    {
    digitalWrite (furnaceControl, LOW);
    digitalWrite (warningLight, HIGH);
    }

  for (int i = 0; i &lt; 10; i++);   // &lt;----- this semicolon is incorrect!
    digitalWrite (i, HIGH);
</code></pre>

<p>The semicolons above (as indicated) terminate the <code>if</code> and <code>for</code> so they don't do anything useful. The lines following them are just unconditional blocks of code which are always executed, once.</p>

<p><strong>Correct:</strong></p>

<pre class="lang-C++ prettyprint-override"><code>  if (temperature &gt; 40)
    {
    digitalWrite (furnaceControl, LOW);
    digitalWrite (warningLight, HIGH);
    }

  for (int i = 0; i &lt; 10; i++)
    digitalWrite (i, HIGH);
</code></pre>
 3917: <p>Nick Gammon correctly points out a problem due to an extra semicolon, but you should also note what the construct <code>else(s &lt; n)</code> is doing.  When the <code>if</code> condition that this <code>else</code> gives an alternative to is false, the statement   <code>(s &lt; n)</code> gets executed.  That statement is an expression statement, and its value is the evaluation of <code>s&lt;n</code>, either true or false.  </p>

<p>If the semicolon after <code>(s &lt; n)</code> weren't there, you'd get a compile error because <code>(s &lt; n) serial.println("north")</code> is not a valid statement.  You may have meant to say <code>else if(s &lt; n)</code> instead of <code>else(s &lt; n)</code>.</p>

<p>Note, in the sequence</p>

<pre><code>if (e &gt; w)
   Serial.println("west");
else if (e &lt; w)
   Serial.println("east");
else if (s &gt; n)
   ...
</code></pre>

<p>that last <code>else</code> typically is reached only rarely, because the only condition to get to it is <code>e</code> and <code>w</code> being equal.  Due to sensor noise and signal processing noise, the chance of <code>e</code> and <code>w</code> being equal is probably at most a few percent.</p>

<p>If your north/south test sequence is supposed to be independent of your east/west test sequence, leave out the second <code>if</code> and second <code>else</code> .  That is, instead say:</p>

<pre><code>if (e &gt; w)
   Serial.println("west");
else
   Serial.println("east");
if (s &gt; n)
   ...
</code></pre>
