Hey everyone, I am trying to figure out how to make it so when a string is inputted into the function along with a start position and character to find, the function will go to the string and look for the character depending on the start position. I was given 3 cases to test out, and 2 of the 3 work. Here is the code below:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
int return_encoded_char(string key, string::size_type &start, char C)
{
int begin_dist = 0;
for(string::size_type i = start; i < key.size(); i++){
if( key[i] == C) {
start = i;
return begin_dist;
}
begin_dist += 1;
}
start = 0;
return key.size() + 1;
}
|
• if the character C is found in key:
o returns an integer that represents the distance required to find the provided character
C in the key (including wrap around).
o otherwise it returns key.size() + 1.
• updates start to the new index (passed by reference)
o if the character is not found, start is updated to 0.
• returns the integer
Here is the sample case I was given:
1 2 3 4
|
2
abcdefghijklmnopqrstuvwxyz
e
7
|
The answer I was getting:
Output I should be getting:
Thank you in advance for any help!