I was set a challenge, and I thought that I had done well, but it appears not.
The challenge was this:
"Write a program that repeatedly asks the user to input a pair of numbers until at least one of the pair is 0.
The function should return the answer to main(), which should report the result.
(The harmonic mean = 2.0 * x * y / (x + y))"
The problem with my simple code is that nothing returns from the function. and when the user types a 0, an infinite loop occurs.
Let's say that I enter x as zero, and y as some other number. Will the loop stop? No. The loop will keep going as long as x isn't zero OR y isn't zero. The only way to stop the loop is to make both x and y zero.
Try
while(x!= 0 && y!= 0)
Now, the loop will keep going if x isn't zero AND if y isn't zero. Making x zero, or making y zero, will break the loop.