joey shertz wrote:Ok I worded it wrong. Is there a way to add all my 1-100 numbers w/o adding 100 arrays?
"You keep using that word. I don't think it means what you think it means
" - Inigo Montoya in "The Princess Bride"
You only have one array
. You mean to say elements
of the array.
Since you have already learned about the for-loop, can you think of a way you can use one to assign increasing values to each successive element of your array? That is, you first declare an array of 100 integers (instead of the 11 that you're declaring now). Then you use a loop to set the value of each of those elements to a number that's bigger than the previous one, if there is any. The only case where there is no previous element is, of course, for the very first element (index = 0).
You need to assign increasing values to your array elements because that's the only way a binary search will work.