You have return 0;inside your while loop. This will cause you to exit during the first iteration of the loop. You may have since you now say you're getting 5 years. Your posted code does not reflect this.
Adding x++ after line 50 is going to cause you to double increment x because you're also incrementing x at lines 23,29,36,43,49. x only needs to be incremented at the bottom of the loop. delete lines 23,29,36,43,49.