Hello all, I have been assigned to make a program that takes a user inputted message and encrypts it from a 2d array of characters. The program needs to take each character from the message and change it with it's corresponding location in the array.
I know I need for loops to increment through the array until it finds the matching character, but I'm not quite sure how to pass each character from the message.
Thanks all, any advice is appreciated!
Example output:
MENU
======
E: Encrypt a message
D: Decrypt a message
Q: Quit
Wow, okay so I just found out you can read strings like arrays. Do i need to use the counter from rows or columns for message[x]?
Edit: Ok so this is the loop I put together but it's only outputting the location of the first character, whats up?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
int i = 0;
for (int r = 0; r < NUM_ROWS; r++)
{
for (int c = 0; c < NUM_COLS; c++)
{
if (message[i] == encryptionMatrix[r][c])
{
cout << r << " " << c;
i++;
}
}
}
}
Alright sorry last one, the decryption is working fine, but for some reason when you finish the input it always adds a 'D' at the end.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
void decryptMessage(char encryptionMatrix[][NUM_COLS])
{
int row; //row location
int col; //column location
cout << "To decrypt, enter the correct sequence of numbers, each followed by a space.\n";
cout << "Then once you are finished conclude with -1 -1\n";
do
{
cin >> row >> col;
cout << encryptionMatrix[row][col];
} while (row != -1 && col != -1); //stops the loop once a negative 1 in row and column are entered
}