This next question is directed at Bauglir.
Generally, that takes the form
int i;
for(i = 0; i < n; i++)
{
some_function(array[i]);
}
where n is the length of your array
Do I need this type of code in order to pass an entire array to a function? It feels more complex than what class showed even though the teacher seems to have not been on point with everything..there was a joke their. By the way if anyone has any tips on how to pass array with structs to functions then that'd be awesome.
No, that code is only necessary to do something like add all the elements of the array. It has nothing to do with passing arrays. Sorry that was unclear. What it does is perform some_function() on each element of the array (in your case, each double in bookARRAY). To add them all, you'd want to do something like
double price = 0;
outside the loop, and then inside the loop replace
some_function(array); with
price += bookARRAY[i];
Then what it means is that the loop will add each element of the array to
price, which finds the sum of all elements in the array.
To pass an array, you simply need to declare the function as everybody's been telling you.
Include the brackets. bookARRAY is of type double[], not double.
EDIT: To explain the loop a bit better. Think about how the program will execute when it reaches it. You have a counter,
i (a common shorthand for "iterator" because this code appears a lot and programmers don't like the extra typing). The loop will end after
i becomes equal to or greater than the length of the array. It starts at 0 and counts up by 1 at each iteration.
At each iteration, it will look at the
ith element of the array
bookARRAY and add it to price. An array's elements begin numbering at 0, so the first iteration with look at the 0th element of the array (that is,
bookARRAY[0]). Now, from what I just said about how
i changes over the course of the loop, you can see that it will select each element of the array exactly once.