Quote Originally Posted by xways
1. do you mean, i dont need those 3 to write that same kind of outcome?
As you found out from reading the "model answer" given to you, indeed you don't need all three, just one. Basically, your first loop reads in values to the array, your second loop computes the sum of values in the array, and your third loop prints the values in the array. So what's important is the array (and hence its name) and where you start (0) and end (days), rather than the name of the index variable that is used for the iteration.

Quote Originally Posted by xways
2. the hint from school was its easier to use an array with 30 elements, also its actually dailyhours not days, even the school had this in the code written.
Then you should ask your school: why 30? Why not 10, or 50? This should have been specified in the requirements.

Quote Originally Posted by xways
3. define 30 with array? how would that work? and why?
You would put this somewhere before the main function, after the includes:
Code:
#define MAX_NUM_DAILYHOURS 30
Then to declare the array:
Code:
float dhrs[MAX_NUM_DAILYHOURS];
As for why: so that readers will know what the 30 means, and you can use it in multiple places such that should you want to change the value, you just change the #define rather than having to do a possibly error-prone search and replace (possibly error-prone because you might get mixed up with 30 used for another purpose).

Quote Originally Posted by xways
are there other commands, which would have made this code even smaller and more efficient?
You can compute the sum while reading the values, but while that would technically make the code smaller and more efficient, it reduces what we call "separation of concerns", i.e., that each part of your code is responsible for that one thing that it is concerned with. It makes no real difference to you now, but as you write bigger and bigger programs and modify them, you'll find that separation of concerns will allow you to write components that are more easily tested and debugged, and so you can have more confidence that your code works. It can also make it easier to understand your code, and allow you to reuse components better, e.g., instead of always having to write a loop to sum values, you might be able to call a function that you have already written.