Upon verification it says "took too long, looks like you have an infinite loop", despite it even showing my output is correct. It is not an infinite loop, I added condition that changes the while condition to false and a break statement(even though one or the other is sufficient) in two places in which the correct output would be met to be sure the program would not be an infinite loop. I have run several tests in another IDE and it runs and ends with no problem. I didn't want to use arrays and was quite happy with the solution I found and am sure it is a correct solution.