Almost 100% certainly, you need to understand this:
http://en.wikipedia.org/wiki/Finite-state_machine[
^],
http://en.wikipedia.org/wiki/State_variable[
^].
As this question (not really clear formulated) is related to the very basics, you need to find out the answer by yourself, through understanding, not through getting an answer. This way, you got a chance to learn at least something. Is it a school assignment? Think about it: you are given a time frame and a chance to learn. Use it well.
Good luck.
—SA