Can someone help me with this? I'm new to C++. Here's my problem. I am to prompt the user to either 'e' encrypt or 'd' decrypt a 4-digit number. Each 4 digit number is to be replaced by the sum of that digit plus 7 (modulus 10). I am having problems trying to determine how to extract each int to perform the necessary calculation. Here's what I have so far:
#include<iostre am>
#include<string >
#include<cstdli b>
#include<cmath>
using namespace std;
int main()
{
char action; // Prompt user to decide action
long encrypt;
long decrypt;
cout << "Enter 'e' to encrypt or 'd' to decrypt" << endl;
cin >> action; // Get user input for action
if (action == 'e')
{
cout << "Enter a 4-digit number to encrypt: " << endl;
cin >> encrypt;
}
else
if (action == 'd')
{
cout << "Enter a 4-digit number to decrypt: " << endl;
cin >> decrypt;
}
else
cout << "INVALID ENTRY! Please enter 'e' to encrypt or 'd to decrypt" << endl;
return 0;
}
#include<iostre am>
#include<string >
#include<cstdli b>
#include<cmath>
using namespace std;
int main()
{
char action; // Prompt user to decide action
long encrypt;
long decrypt;
cout << "Enter 'e' to encrypt or 'd' to decrypt" << endl;
cin >> action; // Get user input for action
if (action == 'e')
{
cout << "Enter a 4-digit number to encrypt: " << endl;
cin >> encrypt;
}
else
if (action == 'd')
{
cout << "Enter a 4-digit number to decrypt: " << endl;
cin >> decrypt;
}
else
cout << "INVALID ENTRY! Please enter 'e' to encrypt or 'd to decrypt" << endl;
return 0;
}
Comment