Its also a very convoluted way of accomplishing the task - you could just use an array with the alphabet in it and then compare the contents of the message passed into the program match the letter to the alphabet array and then shift the index (remembering to wrap around) by whatever the key value is to obtain the ciphertext
This may seem convoluted too to some, but thats how i picture it