Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
1.7 kB
1
Indexable
Never
//Wamia Imtiaz Chowdhury
//z5547070


#include <stdio.h>

int main(void) {
    
    char character;
    char invert_case;
    
    int number;
    

    printf("Please enter a character: ");
    
    scanf("%c", &character);

    printf("Would you like to invert the case? y or n: ");
    
    scanf(" %c", &invert_case);


    printf("By how much would you like to shift the character? ");
    
    scanf("%d", &number);

    char output = character + number % 26;
   
    if (invert_case == 'y') {
        
        if (character >= 'a' && character <= 'z') {
            if (output > 'z') {
                printf("The character is %c!\n", output - 'z' + 'a' - 1 - 'a' + 'A');
            } else {
                printf ("The character is %c!\n", output - 'a' + 'A');
            }
        }  
    
        if (character >= 'A' && character <= 'Z') {
            
            if (output > 'Z') {
                printf ("The character is %c!\n", output - 'Z' + 'A' - 1 - 'A' + 'a');
            } else {
                printf("The character is %c!\n", output - 'A' + 'a');
            }
        }
    
    } else { 
        
        if (character >= 'a' && character <= 'z') {
            if (output > 'z') {
                printf("The character is %c!\n", output - 'z' + 'a' - 1);
            } else {
                printf ("The character is %c!\n", output);
            }
        }   
        if (character >= 'A' && character <= 'Z') {
            
            if (output > 'Z') {
                printf("The character is %c!\n", output - 'Z' + 'A' - 1);
            } else {
                printf("The character is %c!\n", output);
            }
        }
    }
    
    return 0;
}
    
    
    
    
Leave a Comment