0

Please, help me, I can't figure out my problem. This is my code :

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

int main(int argc, string argv[])
{
    //Stop if invalid num of arguments recieved
    if(argc != 2)
    {
        printf("Invalid Iput\n");
        return 1;
    }

    //Get the caesar k value
    int k = atoi(argv[1]);

    //Making sure that interger is not negative
    if(k < 0)
    {
        printf("Invalid Interger !\n");
        return 1;
    }

    else
    {
        string code = get_string();
        for (int i = 0, n = strlen(code); i < n; i++)
        {
            //checking for lowercase
            if(islower[i])
        {
            printf("%c", (((code[i] + k) - 97) % 26) + 97);
        }
        //checking for upercase
        else if(isupper[i])
        {
           printf("%c", (((code[i] + k) - 65) % 26) + 65);
        }
        else
        {
            printf("%c", code[i]);
        }
    }
    printf("\n");
    return 0;
}

enter image description here

  • 1
    What seems to be the problem? What's it doing or not doing? Does it compile? Is there sample output that you can post? – Cliff B Oct 3 '17 at 20:05
  • i cant compile the code. this is the link i'm check50 : cs50.me/checks/14d7124020e4bfed70dcd5b6374b294afaee6b84 – Kris Le Oct 4 '17 at 0:31
  • If it doesn't compile, check50 doesn't help. Can you please edit the question and post a screenshot of the compile output? (NOT check50 output) – Cliff B Oct 4 '17 at 1:09
  • 1
    i cant edit and post in here, i dont know why i cant post my screenshot on. do u have whatsapp or something to sent ? – Kris Le Oct 4 '17 at 1:27
  • Below your post, there is an edit link, at least in the desktop version. There you can click the image button which allows you to upload an image via drag&drop, but in case of text, please refrain from doing screenshot upload, and post the compiler's error messages like the code. And use the {} button after selecting the text, it indents the text so it's shown as a code block. – Blauelf Oct 4 '17 at 16:22
1

You need to check the value of code[i] for case rather than i -

if(islower[i])

i is just a counter.

| improve this answer | |

You must log in to answer this question.

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