0
readability.c:28:9: error: expected expression
    else:

Shown above is the error I am getting. If anyone would point me to what exactly I am doing wrong. that would be great. Bellow, I will add my Readability code written so far.

#include <stdio.h>
#include <cs50.h>
#include <math.h>
#include <string.h>


int main(int argc, char *argv[])
{
    char *string = get_string("Enter a string:\n");
    int i = 0;
    int char_count = 0;
    int alp = 0;
    int word = 0;
    int sentance = 0;
    while(string[i]!='\0')
    {
        if((string[i]>='a' && string[i]<='z') || (string[i]>='A' && string[i]<='Z'))
        {
            alp++;
        }
        else
        {
            if ((string[i] = ' ') || (string[i] = '.') || (string[i] = '!') || (string[i] = '?') || (string[i] = ','))
            {
                word++;
            }
        }
        else
        {
            if ((string[i] = '.') || (string[i] = '!') || (string[i] = '?'))
            {
                sentance++;
            }
        }
        i++;
    }
    printf("%i\n", alp);
    printf("%i\n",word);
    printf("%i\n",sentance);
}

So the error is somewhere on the line 28. I am assuming my "else" statement syntax is wrong, but considering it is identical to the line above, I can't figure out what is wrong. The code worked just fine before the line 28 was added

1 Answer 1

1

if/else is binary. true/false. An If cannot have two else clauses. It needs an else if to add additional conditions, as described here. [The page is for C++, but the lesson is valid in C]

You must log in to answer this question.

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