Help me out please!!! I want to return string with this function, but whenever I try to it just doesn't return anything. I want to store the output of this funtion into a vector after. How do I do all of that?
string encode(string s,int k){
// changed string
string newS;
// iterate for every characters
for(int i=0; i<s.length(); ++i)
{
// ASCII value
int val = int(s[i]);
// store the duplicate
int dup = k;
// if k-th ahead character exceed 'z'
if(val + k > 122){
k -= (122-val);
k = k % 26;
newS += char(96 + k);
}
else
newS += char(val + k);
string encode(string s,int k){
// changed string
string newS;
// iterate for every characters
for(int i=0; i<s.length(); ++i)
{
// ASCII value
int val = int(s[i]);
// store the duplicate
int dup = k;
// if k-th ahead character exceed 'z'
if(val + k > 122){
k -= (122-val);
k = k % 26;
newS += char(96 + k);
}
else
newS += char(val + k);
k = dup;
}
// print the new string
return newS;
}
First can I ask you what is your goal, what do you want to do with the string s?
Also give more context on your parameters, what does k represent?