I\'m creating a Caesar Cipher in c++ and i can\'t figure out how to increment a letter.
I need to increment the letter by 1 each time and return the next letter in t
It works as-is, but because the addition promotes the expression to int
you want to cast it back to char
again so that your IOStream renders it as a character rather than a number:
int main() {
char letter[] = "a";
cout << static_cast(letter[0] + 1);
}
b
Also add wrap-around logic (so that when letter[0]
is z
, you set to a
rather than incrementing), and consider case.