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]