Okay, I haven't done this programming thing in a long while, so I'm coming back to it slowly...
I'm writing an extremely simple word encryption program, that'll I'll improve later, add decryption and more complex algorithms and such, but first I need to debug it. What it's supposed to do is take the word and add one to each letter(ie. abc would become bcd). For some reason, though, which I can't come up with, it just outputs garbage...
Here's the program:
It's pretty self-explanatory, but in case you guys don't get it, which is unlikely, the function char encrypt(char word[40]) at the end of the program adds one to each letter, and then it checks if there is data in the following array entries. If not, it breaks from the loop and returns the encrypted word. I must have done something wrong, though, and I wondered if you guys would mind helping me out on this one.Code:#include <iostream> #include <cstdlib> char collect(void); char encrypt(char word[40]); int main() { char output[40]; output[40] = collect(); output[40] = encrypt(output); std :: cout << "Your encryption of the word is " << output << ".\n"; std :: system("pause"); return (0); } char collect(void) { char word[40]; std::cout << "Input your word.\n"; std::cin >> word; return (word[40]); } char encrypt(char word[40]) { int index; for(index = 0; index <= 40; index++) { word[index]++; if(!word[index]) { break; } } return (word[40]); }
Thanks in advance!(Don't worry. I'll be sure to thank you afterward, also :P)



LinkBack URL
About LinkBacks



