user14356: Im getting stuck in a while loop because Im having trouble running a calculation on some sensor values. When I read my four sensors values and compare the ratio of the first two to the second two, I keep getting 0.00, no matter what the values are. Here's my code:
while ( ( (frontleft + frontright) / (backleft + backright) <= 0.8 ) || ( (frontleft + frontright) / (backleft + backright) > 1.2) ) {
    if (backleft + backright > frontleft + frontright) {
      myStepper2.step(10);
    }
    if (backleft + backright < frontleft + frontright) {
      myStepper2.step(-10);
    }
    int backleft = analogRead(A0);
    int backright = analogRead(A1);
    int frontleft = analogRead(A2);
    int frontright = analogRead(A3);   

    Serial.print("Backleft Reading: ");
    Serial.println(backleft);
    Serial.print("\n");
    Serial.print("BackRight Reading: ");
    Serial.println(backright);
    Serial.print("\n");
    Serial.print("Frontleft Reading: ");
    Serial.println(frontleft);
    Serial.print("\n");
    Serial.print("Frontright Reading: ");
    Serial.println(frontright);
    Serial.print("\n");
    float ratio = (frontleft + frontright) / (backleft + backright);
    float math = (5 + 6) / (4 + 5);
    Serial.print("Math: ");
    Serial.println(math);
    Serial.print("Ratio: ");
    Serial.println(ratio);
    Serial.print("\n");
    delay(500);

  }    

Im getting values for my sensors (backleft, backright, frontleft, frontright), but 'ratio' always comes out 0.00. Because of that, Im getting trapped in the loop I believe. What's going on here? 
Also, just to check, I added 'math' float as that quick calculation, but I'm getting a value of 1.00 in Serial Monitor. Why? It should be 1.222.

user10794: Read this: Integer arithmetic and overflow.
float math = (5 + 6) / (4 + 5);
Serial.print("Math: ");
Serial.println(math);

The compiler is treating your expression (the RH side of the "=" sign) as integers. Thus it is working out:
11 / 9 = 1

Then you assign that 1 to a float. Too late to make it a float! It is already truncated.
Try:
float math = float (5 + 6) / float (4 + 5);
Serial.print("Math: ");
Serial.println(math, 4);  // 4 decimal places

You get:
Math: 1.2222


This also looks wrong:
while ( ( (frontleft + frontright) / (backleft + backright) <= 0.8 ) || ( (frontleft + frontright) / (backleft + backright) > 1.2) ) {
    if (backleft + backright > frontleft + frontright) {
      myStepper2.step(10);
    }
    if (backleft + backright < frontleft + frontright) {
      myStepper2.step(-10);
    }
    int backleft = analogRead(A0);
    int backright = analogRead(A1);
    int frontleft = analogRead(A2);
    int frontright = analogRead(A3);   

How many backleft variables do you have? The one in the while instruction will not be the one you are doing the analogRead on. It doesn't "forward read" variables. I bet you have a different frontleft / backleft etc. set of variables declared earlier. These will not be updated inside the loop.
(To make them get updated drop the word int from inside the loop).

14356: <p>Im getting stuck in a while loop because Im having trouble running a calculation on some sensor values. When I read my four sensors values and compare the ratio of the first two to the second two, I keep getting 0.00, no matter what the values are. Here's my code:</p>

<pre><code>while ( ( (frontleft + frontright) / (backleft + backright) &lt;= 0.8 ) || ( (frontleft + frontright) / (backleft + backright) &gt; 1.2) ) {
    if (backleft + backright &gt; frontleft + frontright) {
      myStepper2.step(10);
    }
    if (backleft + backright &lt; frontleft + frontright) {
      myStepper2.step(-10);
    }
    int backleft = analogRead(A0);
    int backright = analogRead(A1);
    int frontleft = analogRead(A2);
    int frontright = analogRead(A3);   

    Serial.print("Backleft Reading: ");
    Serial.println(backleft);
    Serial.print("\n");
    Serial.print("BackRight Reading: ");
    Serial.println(backright);
    Serial.print("\n");
    Serial.print("Frontleft Reading: ");
    Serial.println(frontleft);
    Serial.print("\n");
    Serial.print("Frontright Reading: ");
    Serial.println(frontright);
    Serial.print("\n");
    float ratio = (frontleft + frontright) / (backleft + backright);
    float math = (5 + 6) / (4 + 5);
    Serial.print("Math: ");
    Serial.println(math);
    Serial.print("Ratio: ");
    Serial.println(ratio);
    Serial.print("\n");
    delay(500);

  }    
</code></pre>

<p>Im getting values for my sensors (backleft, backright, frontleft, frontright), but 'ratio' always comes out 0.00. Because of that, Im getting trapped in the loop I believe. What's going on here? </p>

<p>Also, just to check, I added 'math' float as that quick calculation, but I'm getting a value of 1.00 in Serial Monitor. Why? It should be 1.222.</p>
 10794: <p>Read this: <a href="http://www.gammon.com.au/forum/?id=12146" rel="nofollow">Integer arithmetic and overflow</a>.</p>

<pre><code>float math = (5 + 6) / (4 + 5);
Serial.print("Math: ");
Serial.println(math);
</code></pre>

<p>The compiler is treating your expression (the RH side of the "=" sign) as <strong>integers</strong>. Thus it is working out:</p>

<pre><code>11 / 9 = 1
</code></pre>

<p>Then you assign that <code>1</code> to a float. Too late to make it a float! It is already truncated.</p>

<p>Try:</p>

<pre><code>float math = float (5 + 6) / float (4 + 5);
Serial.print("Math: ");
Serial.println(math, 4);  // 4 decimal places
</code></pre>

<p>You get:</p>

<pre><code>Math: 1.2222
</code></pre>

<hr>

<p>This also looks wrong:</p>

<pre><code>while ( ( (frontleft + frontright) / (backleft + backright) &lt;= 0.8 ) || ( (frontleft + frontright) / (backleft + backright) &gt; 1.2) ) {
    if (backleft + backright &gt; frontleft + frontright) {
      myStepper2.step(10);
    }
    if (backleft + backright &lt; frontleft + frontright) {
      myStepper2.step(-10);
    }
    int backleft = analogRead(A0);
    int backright = analogRead(A1);
    int frontleft = analogRead(A2);
    int frontright = analogRead(A3);   
</code></pre>

<p>How many <code>backleft</code> variables do you have? The one in the <code>while</code> instruction will <strong>not</strong> be the one you are doing the analogRead on. It doesn't "forward read" variables. I bet you have a different <code>frontleft</code> / <code>backleft</code> etc. set of variables declared earlier. These will <strong>not</strong> be updated inside the loop.</p>

<p>(To make them get updated drop the word <code>int</code> from inside the loop).</p>
