user10936: Why does this print output -3? xpos can be any value.
void loop() {
xPos = analogRead(xPin);
yPos = analogRead(yPin);
pwm = xPos*(255/1023);
Serial.println(pwm);

}


user42: The problem is that (255/1023) is being treated as an integer calculation, meaning the result gets truncated to 0. You can make the compiler promote it to a floating-point calculation by explicitly making at least one of the values floating-point. For example:
pwm = xPos*(255.0f/1023.0f);


user3917: The previous answer correctly suggested writing
pwm = xPos*(255.0f/1023.0f);

in place of the original form pwm = xPos*(255/1023);.  But because 255/1023 - 1/4 = -1/1364 which is fairly small (ie it differs by 1 part in 1364), just saying
pwm = xPos/4;

will usually give the correct result or nearly so.  
Note, the following python program shows that this result is exact 514 times as xPos ranges from 0 to 1023, and is one too large 510 times, which for many processes being controlled by PWM signals is close enough.
#!/usr/bin/env python
c = [0]*8
for i in range(1024):
    vf = int(i*255.0/1023.0)
    vi = i/4
    d = vi-vf
    c[d+3] += 1
    #print '{:5} {:5} {:5} {:5}'.format(i, d, vi, vf)
print c


10936: <p>Why does this print output -3? xpos can be any value.</p>

<pre><code>void loop() {
xPos = analogRead(xPin);
yPos = analogRead(yPin);
pwm = xPos*(255/1023);
Serial.println(pwm);

}
</code></pre>
 42: <p>The problem is that <code>(255/1023)</code> is being treated as an integer calculation, meaning the result gets truncated to 0. You can make the compiler promote it to a floating-point calculation by explicitly making at least one of the values floating-point. For example:</p>

<pre><code>pwm = xPos*(255.0f/1023.0f);
</code></pre>
 3917: <p>The previous answer correctly suggested writing</p>

<pre><code>pwm = xPos*(255.0f/1023.0f);
</code></pre>

<p>in place of the original form <code>pwm = xPos*(255/1023);</code>.  But because 255/1023 - 1/4 = -1/1364 which is fairly small (ie it differs by 1 part in 1364), just saying</p>

<pre><code>pwm = xPos/4;
</code></pre>

<p>will usually give the correct result or nearly so.  </p>

<p>Note, the following python program shows that this result is exact 514 times as xPos ranges from 0 to 1023, and is one too large 510 times, which for many processes being controlled by PWM signals is close enough.</p>

<pre><code>#!/usr/bin/env python
c = [0]*8
for i in range(1024):
    vf = int(i*255.0/1023.0)
    vi = i/4
    d = vi-vf
    c[d+3] += 1
    #print '{:5} {:5} {:5} {:5}'.format(i, d, vi, vf)
print c
</code></pre>
