1
    #include <stdio.h>
    #include <cs50.h>
    #include <stdlib.h>
    #include <ctype.h>
    #include <string.h>

    int main (int argc, string argv[])
    {   
        //checks if argc is 2
        if (argc != 2)
        {
            return 1;
        }

        else
        {
            return 0;
        }    

        int k = atoi(argv[1]);

        /* if the key is bigger than 26 it subtracts for new key*/
        if (k > 26) 
        {
            for (int i = 0; i < k / 26; i++)
            {
            k = k - 26;
            return k;
            }
        }



        printf("Please tell me what to encrypt.\n");

        string p = GetString();

        //reiterates each letter
        for (int i = 0, n = strlen(p); i < n ; i++)
        {
            if (isalpha(p[i]), isupper(p[i]))
            {
                int letter1 = p[i]; //sets letter1 to p[1]
                int letter2 = letter1 - 65; //letter1 - the ASCII number for A
                int letter3 = letter2 + k; //letter2 + key
                int result = letter3 + p[i]; //result of letter 3 + p[1]
                /*example: p[i] is 'A' and key = 1
                letter1 = 'A'
                letter2 = 'A' - 65 or 0
                letter3 = 0 + 1
                result = 1 + 'A' or 'B' */
                printf("%c", result);
            }   
            else if (isalpha(p[i]), islower(p[i]))
            {
                int letter1 = p[i];
                int letter2 = letter1 - 97;
                int letter3 = letter2 + k;
                int result = letter3 + p[i];
                printf("%c", result);
            }
            else
            {
                printf("%c", p[i]);
            }
        }
    }
1

Lines 15 through 18 are exiting the program in case you do have what you want. If you have what you want, then just keep going. Don't return anything until you are done with your program.

You can delete this piece (15-18)

else
{
    return 0;
} 

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .