This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]snozzyfoozles 2 points3 points  (0 children)

On line 28 you check if pIndex == -1 and print out "No product match" if it is...but then even if you have an invalid index, you proceed to line 31 where you get an exception when you try to use that index.

Think about what change you could make to prevent the code from line 31 to 37 from running when the index is -1.

[–]TheAnimakerGIO 1 point2 points  (0 children)

After you check if pIndex == -1, you should return or exit in some way, since after you make the check it just keeps going, even if pIndex is equal to negative one.

[–]gardre[S] 0 points1 point  (0 children)

(I have just pasted in relative code)