It continuously prints 2147483647 as the last number of the haystack, even when I use a different seed or no seed at all. Does anyone know why?
-
what is you print loop?– obesmanCommented Jul 3, 2017 at 2:18
-
@obesman How do I format my code? I tried the ` but it didn't work– Joel BanksCommented Jul 3, 2017 at 2:34
-
copy paste, select and click {}– obesmanCommented Jul 3, 2017 at 3:27
-
To format code, see meta.stackexchange.com/questions/22186/…– Cliff BCommented Jul 3, 2017 at 6:20
1 Answer
I will wager that it is printing past the end of the array. Let's assume that there are n numbers to be printed. Does your for loop look something like for(int i = 0; i<=n; i++)
particularly the <=
in the test condition? In other words, are you trying to print array[n]? Remember, the array runs from element 0 to element n-1.
If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)
If not, please edit the question, and add some code. Everyone's crystal balls are in the shop. ;-D