So, I've been through a class in java so I know a little bit of what I'm doing...
The assignment I have is to create a program that takes a string and converts the letters four away in the alphabet (ie: a becomes e and so forth).
I've gotten most of my kinks worked out on my own, but you'll notice my encode and decode are different, I had it set up the way I do for my decode at first and switched to the method I am using in my encode in an attempt to fix my problem with working backwards. now in order to fix my decode I need to fix my circular problem with going past 'a' or 'z' and coming around to the other side of the alphabet.
#include <iostream>
#include <string>
using namespace std;
int main()
{
int choice = 0;
string input;
cout <<"would you like to: \n 1. Decode a message \n 2. Encode a message \n";
cin >> choice;
if (choice == 2)
{
int count = 0, length;
cin.ignore(10000,'\n');
cout << "enter the phrase to be encoded: \n";
getline(cin, input);
length = (int)input.length();
for (count = 0; count < length; count++)
{
if (isalpha(input[count]))
{
input[count]-= 4;
if (input[count] > 'z')
{
input[count] = 'a' + ('z' - input[count]) -1;
}
}
}
}
if (choice == 1)
{
int count = 0, length;
cin.ignore(10000,'\n');
cout << "enter the phrase to be encoded: \n";
getline(cin, input);
length = (int)input.length();
for (count = 0; count < length; count++)
{
if (isalpha(input[count]))
{
for (int i = 0; i < 22; i++)
{
if (input[count] == 'a')
input[count] == 'z';
else input[count]++;
}
}
}
}
cout << "Results: \n " << input << endl;
int (x) = 0;
cin >> x;
}
any help provided would be greatly appreciated. :)