0

Can someone help me with this one ?? I thought I was on the right track, but can't compile. I get the logic but I must be missing something. Appreciate any suggestions. Stepped away from this for a bit and now I am confused and frustrated .

Thanks

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

int main(int argc, string argv[])

{
    // check for correct arguments
    if (argc != 2)
    {
        printf( "incorrect arguments, try again");
        return 1;
    }

    //get key and convert to integer
    int k= atoi( argv[1]);

    // check if integer is non negative
    if ( k < 0)
    {
        printf("incorrect");
        return 1;
    }

    else
    {
        //promtpt user for plaintext p

    p = get_string()
    printf( "plaintext: ");
    }

    for (int=0, n=strlen(p); i<n; i++)
    {
        //check if letter is uppercase or lowercase
        if islower (p[i[]);

        printf("%c", (((p[i] +k -97) %26 ) +97);

        else if isupper (p[i]);

        printf("%c", (((p[i] +k -65)%26) +65);

        else isalpha
        printf(%c, p[i])
    }
    printf ("%c", "ciphertext: "),

    return 0;


}

check50 output

/workspace/pset2/caesar/ $ check50
usage: check50 [-h] [-d] [-l] [--offline] [--checkdir CHECKDIR] [--log] [-v]
               identifier [files [files ...]]
check50: error: the following arguments are required: identifier, files
~/workspace/pset2/caesar/
0

Hmmm.... It looks like you may be trying to use check50 to compile your program. If this is the case, it is incorrect. Use the make caesar command to compile.

The code has numerous errors, mostly missing declarations. Any variable must first be declared before it can be used. A declaration tells the compiler what the variable TYPE is so that it can allocate the correct amount of memory and use it properly.

Also, keywords like int can't be used as variable names.

Many of the remaining errors are simple syntax errors or are "domino errors", or errors created because of an earlier error but would not be an error otherwise. This is why its best to start by solving errors in order. (Fixing one error can sometimes fix a multitude of errors that follow.)

You would probably benefit greatly from a review of the shorts and lectures on creating and declaring variables.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

You must log in to answer this question.

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