Write your question here.
c++ ascii issue. I am only able to encrypt/decrypt 1 word and my assignment is asking my to do the sentence "MEET ME AT 8." I don't know exactly where I am messing up at, please help.
int main()
{
//variables
int i, x, k, u, j;
char str[100];
srand((unsigned)time(NULL));
string answer;
header();
do
{
cout << "Please enter one word:\t";
cin >> str;
cout << "\nPlease choose from the following options:\n";
cout << "1 = Encrypt your word.\n";
cout << "2 = Decrypt your word.\n";
cin >> x;
cin.ignore();
cout << "\nPlease choose from the following options:\n";
cout << "1 = Choose your own key.\n";
cout << "2 = The computer chooses your key.\n";
cin >> k;
cin.ignore();
switch (k)
{
//first case for encrypting a string
case 1:
cout << "\nPlease enter a key using a number between 1 and 35 (only): ";
cin >> u;
case 2:
u = rand() % 35 + 1;
cout << u << endl;
break;
default:
cout << "\nInvalid Input !!!\n";
}
//using switch case statements
switch (x)
{
//first case for encrypting a string
case 1:
for (i = 0; (i < 100 && str[i] != '\0'); i++)
str[i] = str[i] + u; //the key for encryption is 3 that is added to ASCII value
cout << "\nEncrypted string: " << str << endl;
break;
//second case for decrypting a string
case 2:
for (i = 0; (i < 100 && str[i] != '\0'); i++)
str[i] = str[i] - u; //the key for encryption is 3 that is subtracted to ASCII value
cout << "\nDecrypted string: " << str << endl;
break;
default:
cout << "\nInvalid Input !!!\n";
}
cout << "\nWould you like to try another secret message? (yes/no) ";
getline(cin, answer);
} while (answer == "yes");
cout << "\nOh, ok then...Goodbye" << endl;
system("pause");
return 0;
}