Write a sketch with a function that finds the location of a number in an array. First generate an array of 30 elements and display that to the screen with a title of “Original Array”. (You have code that does this). Then write your function that searches that array for the first 5 to be found. That function should take an array and a value, the number being sought, and return the location in the array where it was first found. If it is not found in the array, have the function return -1. Then display to the screen either the location where the number was found (“5 found at location: 2”) or if your function returned -1, display “Nothing Found” on the screen.
HINT: If your loop gets to the end without finding anything, then you can safely presume the number isn’t in the array… 🙂
MAKE SURE YOU RUN YOUR CODE ENOUGH TIMES TO SEE THE “Nothing Found” MESSAGE.
There should be no need for global variables.
And it goes without saying that you should follow the coding style guidelines.
Call your sketch ArrayFind.
Go back to Arrays 2