In light of CS50's plagiarism rules I'll do this in part psuedo code. My question lies within the for loop that iterates through the user's input to translate it into Caesar's cipher. For some reason, when I'm translating lowercase letters into the cipher, I'm getting unpredictable results past the 'e' character. For example, if I run ./caesar 11 and then input the string "austin", the result is l?dety. Then if I run ./caesar 12 and input the same string, the result is l?d?ty. Uppercase letters work fine, though. Running ./ceasar 11 with "AUSTIN", the result is LFDETY.
Here is how my solution is set up:
for(int i = 0, n = strlen(user_input); i < n; i++)
{
// code equals user_input[i]
// if code is between A and Z
{
code = code + user_key % 26;
// if this is greater than Z
{
// get the amount overflowed and add it to A - 1
}
}
}
As I stated previously, this code works fine. Immediately after this, I run a second if statement for lowercase letters. They are identical except for the case. Can anyone tell me why the lowercase letters won't output properly past the 'e' character? I've tried it a bunch a different ways and I seem to have hit a wall, so this is a last resort. I'd appreciate any help. Thanks!
Edit: made a mistake when I converted to pseudocode