Method in Double For-Loop becomes infinte loop
<p>I need the method pointInPolygon() to accept values and return true or false if the the pints are in the polygon. The method works perfectly correct if i specify the values manually. But the issue is when i want the values to be processed automatically.
I use one for-loop to go through the x values and another loop to go through y values
but in the end, it becomes as an infinite loop. can you experts help me. </p>

<p>Please assist. </p>

<pre><code>int polySides  = 4;
float polyX[]    =  {4,4,15,15};
float polyY[]    =  {4,20,20,4};

#include &lt;iostream&gt;
using namespace std;

int main(){
bool pointInPolygon(int,int) ;

for(int x=4;x&lt;15;x++){
for(int y=4;y&lt;20;y++){
cout&lt;&lt;pointInPolygon(x,y) ;
  }
 }
} // End of Main()




bool pointInPolygon(int x,int y) {
  int i, j=polySides-1 ;
bool oddNodes=false     ;

for (i=0; i&lt;polySides; i++) {
if (polyY[i]&lt;y &amp;&amp; polyY[j]&gt;=y ||  polyY[j]&lt;y &amp;&amp; polyY[i]&gt;=y) {
if (polyX[i]+(y-polyY[i])/(polyY[j]-polyY[i])*(polyX[j]-polyX[i])&lt;x) {
   oddNodes=!oddNodes; }
 }
j=i; }

 return oddNodes; 
 } 
</code></pre>
