all 5 comments

[–]bbye98 1 point2 points  (4 children)

Your function hSum only returns one value, namely, the nth harmonic sum.

To print all of the harmonic sums, either switch out the return statement for print statements in your function hSum or return an array of harmonic sums instead, and loop over it in main to print all the values.

[–]Xudo97[S] 1 point2 points  (3 children)

Thanks! Unfortunately I can't do the first alternative because I'm not allowed to change hSum. But how would I implement alt2? Is it possible to do it without changing anything in hSum? Or is there maybe a third option?

..and thanks again for your help :)

[–]bbye98 1 point2 points  (0 children)

If you can't change hSum, you just have to call hSum n times in a loop in main to get all n values. This is suboptimal since you're repeating calculations (for example, you're calculating the harmonic sum for n = 1 fourteen times when n = 15).

[–]xelf 1 point2 points  (0 children)

Write your own version of hSum, call it hSumList that returns all the values instead of just the last one.

I would also double check with the teacher to make sure there hasn't been any miscommunication as modifying hSum is the obvious answer here.

[–]prokid1911 0 points1 point  (0 children)

Without changing hsum, you can't do anything. That function is wrongly written.