View Single Post
Old 03-21-2011, 07:58 PM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,567
Thanks: 62
Thanked 4,058 Times in 4,027 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Code:
			for(i=0;i<=numPoints;i++){
				if(y[i]>=0 && y[i+1]<0){
					change[numChange]=i;
					numChange++;
				}
				else if(y[i]>0 && y[i+1]<=0){
Your other loops only went to i < numPoints. With this loop, you are guaranteed to be 1 past the end of the array.

But then you make it worse:
How can you use i+1 if i is already at or past the maximum value for the array subscript??
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Users who have thanked Old Pedant for this post:
Fot (03-23-2011)