Tip
If you are keeping track of multiple variables tied to one object (such as one player’s
different stats from a single game in this code example), a structure can help tie things
together nicely. You learn about structures in Chapter 27, “Setting Up Your Data with
Structures.”
Both example programs in this chapter use a sequential search because the arrays (customer ID and
gameScores) are searched from beginning to end until a match is found. You’ll learn about more
advanced searches as your programming skills improve. In the next chapter, you’ll see how sorting an
array helps speed some array searches. You’ll also check out advanced search techniques called
binary searches and Fibonacci searches.
The Absolute Minimum
The goal of this chapter was to show you how to find values in arrays. You saw how to
find array values based on a key. The key is a value that the user enters. You’ll often
search through parallel arrays, as done here. One array (the key array) holds the values
for which you’ll search. If the search is successful, other arrays supply needed data and
you can report the results to the user. If the search is unsuccessful, you need to let the
user know that also. Key concepts from this chapter include:
- Filling arrays is only the first step; after they’re filled, your program must interact
with the data. - Until you learn more about searches, use a sequential search because it is the easiest
search technique to master. - Don’t forget that a match might not be found. Always assume that your search value
might not be in the list of values and include the code needed to handle an unfound
value.