This is my first post here! Woot. Just so you all know, I've read most-all of the tutorials on this website, the entire 7 book C++ for dummies, and am fairly well into Effective C++ (chapter 3 to be precise). HOWEVER, this is my first real program. I'm not going to bother to explain how that worked out.
Anyways, the program I'm writing is supposed to decode "secret messages". Here's the code I'm having an issue with:
It compiles fine, but when I run a Debug, it shoots me a breakpoint at the line char returnChar = letters[i - 1]; and it says that it's because i = 50. I've tried checking everything possible, and i even equals what it should (8, fyi) right when the char function is being called (during the if statement). I have absolutely no idea why it's so determined to set i to 50, but it shouldn't be doing that and it's making me very angry. I've tried using a reference-by-pointer instead of a reference-by-value, but it didn't help. I also tried declaring a const int a = i right before it sends, but it still somehow changes the int from 8 to 50. Now THAT I really need to have explained to me.
It's a little hard to trace your code if there's only a fragment of it. Breaking at that line does not really help because you could've had more than one calls and I can not tell when and what situation was the function called.
Also, I do not know why you have your if statement like this
if(letter = true)
You are assigning true to a variable then you test the variable. It's the same as saying as
if(true)
or not having that test statement there at all. You probably want it to be just this way
1 2 3 4
if (letter) {
i = ((*randomnum * *randomnum) + *entrynum - (i / *randomnum));
translation += fTNumToChar(i);
}
What compiler are you using? The only thing I can add to what vince1027 posted above is to suggest that you try using a compiler that allows you to step through your code and track the variable value at each step. That will show you EXACTLY where the value is changing, making troubleshooting much easier. Visual C++ Express, or Dev-C++ will both enable you to do that. I mention those two specifically because they're both available for free download. (Just Google them if you're interested.) As mentioned above, it's very difficult to troubleshoot your code from the fragment presented. If you want some more specific help, post more of your code.