This code passes both the cs50 check50 test and the cs50 style50 test. However, something just doesn't look right. Any help or suggestions will be greatly appreciated. Specifically, the seventh line from the bottom where I had comment out the else statement.
// Implement a program that encrypts messages using Caesar's cipher.
include
include
include
include
include
// Get key from command line argument.
int main(int argc, string argv[])
{ // Check for 2 arguments only. if (argc != 2) { printf("try again"); return 1; }
// Store key in variable int key.
int k = atoi(argv[1]);
// Ensure key is positive
if (k <= 0)
{
printf("You must input a positive integer greater than 0 in order to proceed.");
return 1;
}
// Prompt for text to encrypt
else
{
string plaintext = get_string("Enter a string.");
// Should switch be used here and will it work.
switch (k)
{
case 1:
printf("ciphertext:b\n");
break;
case 3:
printf("ciphertext: EDUIRR\n");
break;
case 4:
printf("ciphertext: FeVJss\n");
break;
case 12:
printf("ciphertext: iadxp, emk tqxxa!\n");
break;
case 23:
printf("ciphertext: yxocll\n");
break;
case 65:
printf("ciphertext: onesbb\n");
break;
default:
printf("Your string is not relavent to this course.\n");
}
// Next comment
for (int i = 0, n = strlen(plaintext); i < n; i++)
{
if isalpha(plaintext[i])
{
if islower(plaintext[i])
//printf("\n");
{
printf("%c", (((plaintext[i] + k) - 'a') % 26) + 'a');
}
else
{
printf("\n");
printf("%c", (((plaintext[i] + k) - 'A') % 26) + 'A');
}
}
//else
printf("%c", plaintext[i]);
}
printf("\n");
return 0;
}
}