((ch-‘A’) + k) % 26 + ‘A’
to calculate the encrypted version of an upper-case letter, where k is the key (i.e., the shift amount). You will need a similar expression for lower-case letters.
I am having a lot of trouble trying to figure this out, and we are supposed to be using arrays
when i try to compile i get error and cannot figure out what I am doing wrong#include <stdio.h>
#include <string.h>
Expand|Select|Wrap|Line Numbers
- int main()
- {
- int shift;
- char message[80];
- printf("Enter message to be encrypted: ");
- scanf("%s", &message);
- printf("Enter shift amount (1-25): ");
- scanf("%d", &shift);
- for(int i=0;i<strlen(message);i++)
- {
- if (message[i]=!' ')
- if('A'>= message[i] <= 'Z')
- {
- message[i] = ((message[i]-'A') + shift) % 26 + 'A';
- }
- else if('a'>= message[i] <='z')
- {
- message[i] =((message[i]-'a') + shift) % 26 + 'a';
- }
- }
- printf("Encrypted message: %s", message);
- return 0;
- }