i have the following code which works, well its suppose to shift the letters of a text file by whatever the user wants, lets say the text file says "hi" if the user wants to shift the letters by 1 to the right it will become "ij"
ok but the problem is when i want to shift a letter that goes over the alphabet, like lets say the word is "zoo" if i want to shift it by one the letter z will give me a random character that i dont want, the whole word should become "app"
anybody wants to help me fix this??
void rotateEncrypt(vector<string> V1, vector<string> V2, int rotKey)
{
char ch;
int k;
string word = V1[0];
for (unsigned i=0; i<word.size();i++)
{
if(word[i]!=' ')
{
ch = tolower( word[i]);
ch = ch + rotKey;
word[i] = ch;
if(ch > 'z');
k = ch -'z';
ch = 'a'+k - 1;
word[i] = ch;
}
}
V2.push_back(word);
ofstream fo("simpler.txt" ,ios::app);
fo<< word <<'\n';
fo.clear();
fo.close();
}