This program is supposed to encrypt and decrypt the string "myWord". Once received, it passes through the two methods to encrypt and decrypt and then returns to main. I have been trying to make it prompt the user if they want to continue or not. If they enter "n" then the loops stops and the program ends. if they enter "y" then it will repeat and they will be able to encrypt again after they are prompted for their name again. I've tried many different ways but the output continues to end up like this after I enter y:
#include <iostream>
#include <string>
using namespace std;
void encrypt(string);
void decrypt(string);
int main() {
string myWord;
char choice = 'y';
while (choice == 'y') {
cout << "Enter a name: ";
getline(cin, myWord);
encrypt(myWord);
cout << "Would you like to encrypt again? (y/n): ";
cin >> choice;
if(choice == 'n') {
return 0;
}
system("pause");
}
return 0;
}
void encrypt(string encrypting) {
for (int i = 0; encrypting[i] != '\0'; i++) {
encrypting[i] = encrypting[i] + 1;
}
cout <<"Encrypted: " << encrypting << endl;
decrypt(encrypting);
}
void decrypt(string decrypting) {
for (int i = 0; decrypting[i] != '\0'; i++) {
decrypting[i] = decrypting[i] - 1;
}
cout << "Decrypted: " << decrypting << endl;
return;
}
My output