In normal C programming the entry point is main(). That is, main() is called once and execution continues from there. If your program was renamed main() and dropped into a normal C programming environment it has a good chance to work as expected.
In the Arduino paradigm there are 2 entry points. A function called setup() which is called once. And a function called loop() which is called repetitively. The assumption is that the latter method is easier for beginner programmers to understand.
What you have done is created and initialized your key variables which track the state of your program in the Arduino loop() function. This function will be called over and over again by the Arduino firmware already programmed into the processor. This causes your key variables to be recreated and reinitialized each time the function loop() is called.
Consider moving the creation and initialization of your key variables to the setup() function. In this way they will only be created and initialized once.