0

Here is my code for caesar:

#include <cs50.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main(int argc, string argv[])
{
    if (argc!=2)
    {
        printf("Error!\n");
        return 1;
    }

int k = atoi(argv[1]);
string s=GetString();
int n=strlen(s);
for(int i=0;i<n;i++)
{
   if (('A'<=s[i]) && (s[i]<='Z'))
   {
       char a= s[i]-65;
       char b= (a+k)%26;
       char c= b+65;
       printf("%c",c);
   }
   else if (('a'<=s[i]) && (s[i]<='z'))
   {
      char d= s[i]-65;
      char e= (d+k)%26;
      char f= e+65;
      printf("%c",f); 
   }
   else
   {
       printf("%c",s[i]);
   }
}
printf("\n");
return 0;

}

And when i check my file by cs50 i get the following message:

:) caesar.c exists

:) caesar.c compiles

:( encrypts "a" as "b" using 1 as key \ expected output, not a prompt for input

:( encrypts "barfoo" as "yxocll" using 23 as key \ expected output, not a prompt for input

:( encrypts "BARFOO" as "EDUIRR" using 3 as key \ expected output, not a prompt for input

:( encrypts "BaRFoo" as "FeVJss" using 4 as key \ expected output, not a prompt for input

:( encrypts "barfoo" as "onesbb" using 65 as key \ expected output, not a prompt for input

:( encrypts "world, say hello!" as "iadxp, emk tqxxa!" using 12 as key \ expected output, not a prompt for input

:) handles lack of argv[1]

2 Answers 2

0

I think you might need to use 97 instead of 65 for lowercase. Looks like your prompting for an output according to check50

1
  • Also, review the spec and make sure your output matches the specified output. Looks like you are missing a couple of the "Your program must...." directives. Jan 11, 2017 at 13:44
0

Apart from the edits suggested by @AndyStevens, I would also point out that, You first need to verify whether k has only digits or not. Immediately type-casting string to integer using atoi without verifying whether each character is digit or not will fail some check50 test-cases

You must log in to answer this question.

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