state machine with C++. for practice