Hi, I'm busy with an exercise for a course. Ik have to make ap program that codes tekst by changing the letters from the alphabet. f.e. Key = 2, so a is c and l is n etcetera.
Now I want the uppercase letters tot remain uppercase ande the lowercase letters lowercase. I thought I had a nice solution, but it doesn't work. What am I doing wrong?
insert
Code:
#include <cs50.h>
#include <stdio.h>
int main(void)
{
int key;
//get key//
do {
printf("Enter your key (0-26)\n");
key=get_int();
}
while (key<0 || key>26);
//get plaintext//
char text[50];
printf("Enter your massage (max 50 characters): ");
fgets(text, sizeof(text), stdin);
//encipher//
int x;
for(x=0;x<50;x++)
{
if (isupper(text[x]))
{
printf("%c",(text[x]+key)%97);
}
else if (islower(text[x]))
{
printf("%c",(text[x]+key)%65);
}
else
{
break;
}
}
return(0);
}