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

int main(int argc, string argv[])  
{  
    if (argc == 2)  
    {  
        int key = atoi(argv[1]);  
        printf("plain text:");  
        string text = get_string();  
        printf("cypher text:");  
        for(int i = 0, n = strlen(text); i < n; i++)  
        {  
            if (isalpha (text[i]));  
            {  
                if (islower (text[i]));  
                {  
                    printf("%c", ((text[i] + key - 97)/26 + 97));  
                }  
                else if (isupper (text[i]));  
                {  
                    printf("%c", ((text[i] + key - 65)/26 + 65));  
                }  
            }  
  **ERROR HERE** else **( It says expected expression and thats it )**   
            {  
                printf("%i", text[i]);  
            }  
            printf("\n");  
            return 0;  
        }  
    }  
    else  
    {  
        printf("Enter a single key  to incypher text using caesar algorithm\n");  
        return 1;  
    }  
}
0

Simple error(s). If you look at each of your if and else if statements, you have added a semicolon to the end, followed immediately by the opening curly brace on the next line. This is disrupting the link between the if statements and the code block to be executed if true. The semicolon ends the statement, so the code is basically saying "if the test condition is true, do nothing", and the curly braces only serve to define a code block that would always be executed.

Remove the semicolons and that should clean up a lot of issues. There may be more problems, but that would be for a new question. ;-)

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

You must log in to answer this question.

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