Debug Problem? PLEASE HELP

ddd
Last edited on
I think the problem is with the while loop?
I've been working on it a lot, haven't solved the problem. I've identified it's wi
Last edited on
bump
The problem is probably reverseMessage(message);. I don't know what may cause an error...
:( anyone else have any idea?
Remember, the last valid index in a string = length - 1.

Same with all STL containers.

1
2
3
	string example = "Hello!";
	int len = example.length();
	char check = example[len - 1];


check = '!'
Last edited on
PS trivia?

It's more usual to align else ifs with the if they're an else of, esp when they all test the same variable in a similar way. For example:

1
2
3
4
5
6
7
8
9
10
11
12
13
void exchangeCHAR(char msgCHAR)
{
	if(msgCHAR == 'A' || msgCHAR == 'a')
		msgCHAR = '~';
	else if(msgCHAR == 'e' || msgCHAR == 'E')
		msgCHAR = '|';
	else if(msgCHAR == 'i' || msgCHAR == 'I')
		msgCHAR = '\'';
	else if(msgCHAR == 'o' || msgCHAR == 'O')
		msgCHAR = '{';
	else if(msgCHAR == 'u' || msgCHAR == 'U')
		msgCHAR = ']';
}


This makes it easier to see all the tests are close relatives of each other.
Last edited on
Remember, the last valid index in a string = length - 1.

Same with all STL containers.


Thanks for the example. I think I understand; so exchangeCHAR should be exchangeCHAR(message[msgLength-1]), but I still get the error!

also, thanks for your tip. I'll make sure to follow that.
Your loop at line 70 definitely needs to change, the other posters in this thread gave some good advice there, however your function exchangeCHAR needs a bit of work also. The way it stands at the moment, it won't have any effect. When you pass a variable to a function by value, the function makes a local copy of that variable. That is what you are changing in your function. That means it won't have any effect on the original char variable. You will need to use a pointer or a reference to a char to make it work. I would recommend using a reference, since you would only need to change "char msgChar" to "char& msgChar"
Your loop at line 70 definitely needs to change, the other posters in this thread gave some good advice there, however your function exchangeCHAR needs a bit of work also. The way it stands at the moment, it won't have any effect. When you pass a variable to a function by value, the function makes a local copy of that variable. That is what you are changing in your function. That means it won't have any effect on the original char variable. You will need to use a pointer or a reference to a char to make it work. I would recommend using a reference, since you would only need to change "char msgChar" to "char& msgChar"


Thanks so much for the tip! However, even after making the change you suggested as well as the change that the previous poster suggested I still get an error! I'm sorry for being a bother, but I just can't understand what is wrong.
Topic archived. No new replies allowed.