2 Attachment(s)
[RESOLVED] Novice nested loop issue
I'm writing a series of basic decipher programs and I have run into an issue where I get the correct answer when I start the loops at the iteration that contains the correct answer.
Obviously I'm new here so if there are any issues with the way im posting this problem feel free to point them out. :p
Code:
// generate key "words" with length of 3
for (int x = 0; x < 26; x++){
for (int y = 0; y < 26; y++){
for (int z = 0; z < 26; z++){
for (int i = 0; i < arraySize; i++){
if (text[i][0] >= 97 && text[i][0] <= 122){
if ( keyPos == 0 ){
text[i][1] = (text[i][0] - x);
if ( text[i][1] < 97 ){
text[i][1] = (text[i][1] + 26);
}
keyPos++;
}
else if (keyPos == 1){
text[i][1] = (text[i][0] - y);
if ( text[i][1] < 97 ){
text[i][1] = (text[i][1] + 26);
}
keyPos++;
}
else if (keyPos == 2){
text[i][1] = (text[i][0] - z);
if ( text[i][1] < 97 ){
text[i][1] = (text[i][1] + 26);
}
keyPos = 0;
}
}
else {
text[i][1] = text[i][0];
}
}
if (x == 17 && y == 7 && z == 12){
for (int i = 0; i < arraySize; i++){
cout << text[i][1] << int(text[i][1]) << " ";
}
cout << "\n\n";
}
}
}
}
This is the essence of the loop, I've attached the program in its entirety if necessary. Basically what happens is if I start the loops at x = 17, y = 7, z = 12, then I get the correct decipher shifts but if I start at 0,0,0 whenever it gets to that iteration (12,000 ish) the shifts are off by 2 or 3. :ehh: "koq" should translate to "the" but im getting "dcz". Is this a simple bug in the or is something moving to fast for something else to keep up?
Thanks for the input!! :)
Attachment 31041
Attachment 31043
Re: Novice nested loop issue
Have you tried to debug your program using the debugger to understand why it's not working as expected? You mention nothing about this. If the program does not do what you expect, you start by debugging your code. After you have done this and you still have a query about the c++ language and its use, then come back to us.