i know the following function is not correct, but its suppose to read a text file(which containts the words "hello all") and pass it to a Vector
called V1 and then encrypt it and pass the encryption to a second vector called V2 and finally output the result into a different text file.that text file should be "ifllp bmm" , which means that the file is being encrypted using ciphers method. Can anyone help me fix it??

void rotate(vector<string> V1, vector<string> V2, int rotKey)

{
string original;
ifstream fin;
fin.open("simple.txt");
string word = V1[0];
word[0];
for (int i = 0; i < V1.size(); i++)
{
char ch = word[i];
ch = tolower(ch);
ch = ch + rotKey;// lets say i want to shift the letter by one to the right
if(ch > 'z')
{
int k = ch -'z';
ch = 'a'+'k' - 1;
}
word[i] = ch;
V2.push_back(word);
}
}

Not sure I understand the algorithm.

"hello all" turns into "ifllp bmm". Is that a mistake? Is it supposed to be:

"ifmmp bmm"? Add one to each letter?

yes it turns into that and yes its suppose to add one to each letter , well actually add whatever the user wants to add . thats why the rotKey is there.

At minimum, lines 16 and 17 are incorrect. The way you have it, line 16 calculates something that is never used, so you can delete it. Putting 'k' in quotes doesn't make sense to me. It has no relationship to the variable k in line 16. If you want to use the variable, get rid of the quotes around 'k'. I imagine that's what you are trying to do.

This article has been dead for over six months. Start a new discussion instead.