Trying to encode something.

closed account (365X92yv)
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?
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.
closed account (365X92yv)
Good call. Forgot about the header. Thanks.
Topic archived. No new replies allowed.