Summary of task: I have to write a program that adds 3 places to each char of a user input string to encrypt and vice versa for decrypting. Doesn't seem to hard, but as a beginner I am having an issue. I am having problems getting the user input string to convert so that I can add or subtract three places from it. So if the letter is A it should come out a D if encrypted. The error I am getting when compiled is
Encryption2.cpp:54: no match for `string & - char'
Here is my source code for this program.
//Encryption/decryption program that encrypts or decrypts
//user input as a string.
#include <iostream>
#include <string>
string encrypt(string text, string message);
string decrypt(string text, string message);
using namespace std;
char choice;
int main()
{
//Ask user to encrypt or decrypt
cout << "Would you like to encrypt or decrypt?" << endl;
cout << "Enter E for encrypt or D for decrypt." << endl;
cin >> choice;
if (choice == 'E')
{
encrypt;
}
else if (choice == 'D')
{
decrypt;
}
return 0;
}
//Encrypt the text
string encrypt(string text, string message)
{
int i;
string temp;
cout << "Enter the text you wish to encrypt." << endl;
cin >> text;
for (i = 0; i < message.length(); ++i)
temp = 3 + (text - '0') << endl;
cout << "Encrypted text is " << temp << endl;
}
//Decrypt the text
string decrypt(string text, string message)
{
int i;
string temp;
cout << "Enter the text you wish to decrypt." << endl;
cin >> text;
for (i = 0; i < message.length(); ++i)
temp = 3 + (text - '0') << endl;
cout << "Decrypted text is " << temp << endl;
}