Stop and think about what you are doing.
When you enter a number, it could be the largest so far, or the second largest, or smaller than either.
So you need two independent tests:
Is it larger than the largest?
If it is, then the previous largest is automatically the second largest, and teh largest becomes the new value.
Other wise, is it larger than teh second largest?
If it is, the second largest becomes the new value
Otherwise, ignore it.
That gives you the results you want, but I'd argue that 0 is a bad value to initialize to. I would use the constant value
INT_MIN
:
C++ Integer Limits[
^] which will give you the smallest possible value that can be entered - which may be a lot smaller than zero!