Trying to encode something.
Jan 28, 2012 at 9:49am UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
string encode_message(string message, string key)
{
string answer;
char sub;
char orig;
//for each letter in message
for (int i=0;i<message.length();i++)
{
orig = message.at( i );
cout << orig;
find_sub(orig, key);
//sub = find_sub(message.at( i ), key);
//answer.append(1, sub);
}
return answer;
}
// take letter and key, return substitute letter
char find_sub(char letter, string key)
{
char position;
if (letter >= 97 && letter <= 122)
{
position = letter - 97;
return key.at(position);
}
return letter;
}
Trying to pass a char and the key into find_sub but I get a cannot convert from char to string error message. Any ideas?
Jan 28, 2012 at 10:02am UTC
This looks right based on how find_sub() is defined. Check the declaration above encode_message() or in the header. If you've changed the definition, but forgot to change the declaration, you'll get this problem.
Jan 28, 2012 at 10:20am UTC
Good call. Forgot about the header. Thanks.
Topic archived. No new replies allowed.