There is a bug in both functions used to calculate the transformation - within the while loop (which checks state), there is a switch-case statement, which checks the value of state. Then, within case (state==2), there is an if-else statement that checks if state is 1 or 2, and depending on that, updates the value of state. The case 1 statement is missing a break, so when state == 1 the code goes to the if-else and then executes code within if state==1. Then the rest of the code within case state==2 is executed, which seems suspicious.
My first guess was that the if state==1 piece is supposed to be within the code section of the case statement where state ==1, and then we add a break. However I just determined this does not work, so I am investigating what the likely correction is. It would be helpful to get the author's input as to the intended behavior.
There is a bug in both functions used to calculate the transformation - within the while loop (which checks state), there is a switch-case statement, which checks the value of state. Then, within case (state==2), there is an if-else statement that checks if state is 1 or 2, and depending on that, updates the value of state. The case 1 statement is missing a break, so when state == 1 the code goes to the if-else and then executes code within if state==1. Then the rest of the code within case state==2 is executed, which seems suspicious. My first guess was that the if state==1 piece is supposed to be within the code section of the case statement where state ==1, and then we add a break. However I just determined this does not work, so I am investigating what the likely correction is. It would be helpful to get the author's input as to the intended behavior.