C++ Simple Encryption won't display array

nothingasis

In Runtime
Messages
198
Location
CA
So I'm supposed to create an array of size 8. Replace each digit by (the sum of that digit plus 7) modulus 10. Then, swap the first digit with the third, swap the second digit with the fourth and print the encrypted integer.

I can't seem to understand why my array of values aren't showing up. Can anyone help? Please and thank you! :)

http://pastie.org/6192395#
 
Last edited:
Ok so, I'm just gonna start off by saying that I am still a student in C++ but I want to 'try' to help just because I may learn something =) {Keyword is try, hopefully someone else with more experience might help you once they see the thread maybe?}

Anyways, look's like you created/have an 'Encrypt' class. I am going to assume you have the Digits[] array declared in the header as a private or something cause otherwise you'd get errors that way.

Also, I noticed on your loops you are using "x =! 4" . So when the X value does not equal 4, the loop exits. If you are trying to get it to go up to 4, suggest using
for(int x = 0; x < 4; x++) instead, as that let's it go up to 4 (o, 1, 2, 3 then exits). I believe x=!4 exit's immediately and doesn't allow for any data to be entered nor array's to be shown since x always starts out at 0.

Edit: or am I thinking =! is the same thing as != o_O
 
Okay so a couple thing I've noticed after debugging the entire program step by step.

It didn't go through the loop, my elements [4-7] were not being assigned any values because it didn't go through any loops for the encryption.

One important thing was your mentioning of the conditions so I changed them all and finally it spewed out some values. Granted the encrypted values were not correct but I'm sure it's an easy fix. I'll post of the results if anything. Thank you for the suggestion I really appreciate it! :)

[EDIT] Problem is now with the for loop for encryption, I have an inside four loop which I misunderstood when writing it out.

So this should be the proper loop and encrementing for the encryption. Also, I've noticed that the two first elements of the array should be switched around but just wanted to post this first.

int j = 0;
for(int i = 7; i > 3; i--)
{
digits = digits[j] + 7;
digits = digits % 10;
j++;
}
 
Last edited:
I went ahead and wrote this based on your problem description. It's a quite simple one-file program, except it uses double instead of integer but that shouldn't be too much of a problem, it works fine with integers too.
 
Last edited by a moderator:
Back
Top Bottom