I have to write a program that will essentially return a character that is 13 places forward or backward. It only works for characters in the alphabet and if it's lowercase, it stays lowercase and if it's uppercase, it stays uppercase.
char char_rot_13(char c);
What I've done so far is I've made two conditional statements, one for lowercase and one for the uppercase characters from a to z. Then I returned, in each one, new_character = c + 13. But when I tried a test case with 'W', the test failed.
char char_rot_13(char c)
{
char new_c;
if (c >= 'a' && c <= 'z')
{
new_c = c + 13;
}
else if (c >= 'A' && c <= 'Z')
{
new_c = c + 13;
}
return new_c;
}
The problem lies here
new_c = c + 13;
ROT-13 is rotation instead of just addition.
For example, rot13('a')
should be 'a'+13,
but rot13('W')
should be 'W'-13 instead of 'W'+13.