Addition of another else if and correction of other else if statement to give proper result