What I'm thinking is that I need to write a command parser and then just jump out to a function depending on what the input command is. So the original code (minus the input and output parts) just gets mapped to a series of functions.
That's not an unreasonable solution -- one possible way to (begin to) implement it has been discussed here.