I have 4 functions:
encrypt()
, decrypt()
, generate_key()
and menu()
.
The menu just asks the user what action to perform and using if and else if it will execute the selected function like this:
if (choice == 1) {
encrypt();
menu();
}
So what will happen is that the encrypt()
function should execute first and after it finishes executing, it will go back to the menu by calling the menu()
function.
Now this is my encrypt()
function:
int encrypt() {
// Ask the user for a message to encrypt and the key to use
std::cout << "Enter a message to encrypt: ";
std::string message;
std::cin >> message;
std::cout << "Enter a key to use: ";
int key;
std::cin >> key;
// Encrypt the message
std::string encryptedMessage = "";
for (int i = 0; i < message.length(); i++) {
encryptedMessage += (message[i] + key);
}
// Print the encrypted message
std::cout << "Encrypted message: " << encryptedMessage << std::endl;
return 0;
}
From what you see here, the program should ask for a message and the user enters one then asks for key and enters a key as well, then it would "encrypt" the message and print it. But what happens is that it asks for a message and then after the user enters one, asks for key, however when you enter the key, the application just closes with no error messages, no nothing. I'm really clueless and don't know what I'm doing wrong.
There's my full code: https://paste.ubuntu.com/p/NdVTKmcg9J/