0

Okay, I know there is a prior article about this, but I used { } with my if statements, and it's still not working... is it because I have multiple if statements consecutively after another?

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

    int i, n,t, s[51],p=1,a,b,c; 
int main() {
            srand(1);
        for(i=0;i<=51;i++) {
            if (p>13)           {
                p=1;            }  
                s[i] = p;
                p++;
                           }
printf("\n");
  for(i=0;i<52;i++) {
  a = n;  
  n = rand()%52;
    if (s[n]<0 || s[a]<0)  {
                --i;            }
    else    {
        if ((s[n]=1)) {  
            b=11;
            printf("A + "); }
        else if (s[n] == 11); {  
            b=s[n];
            printf("J + "); }
        else if (s[n] == 12); {   
            b=s[n];
            printf("Q + "); }
        else if (s[n] == 13); {       
            b=s[n];
            printf("K + "); }
        else {  
            b=s[n];
            printf("%i + ",b); }

        if ((s[a]=1)) {  
            c=11;
            printf("A = "); }
        else if (s[a] == 11); {  
            c=s[a];
            printf("J = "); }
        else if (s[a] == 12); {   
            c=s[a];
            printf("Q = "); }
        else if (s[a] == 13); {    
            c=s[a];
            printf("K = "); }
        else {  
            c=s[a];
            printf("%i = ",c); }

        if((b+c=21)){
            printf("%i blackjack!\n",b+c);
                    s[n]=-1;
                    s[a]=-1;}
        else{
            printf("%i\n",b+c);
                    s[n]=-1;
                    s[a]=-1;                          
                    }
            }
                    }
 return 0;  }

these are the errors I'm coming up with:
p2.c:29: error: 'else' without a previous 'if'
p2.c:32: error: 'else' without a previous 'if'
p2.c:35: error: 'else' without a previous 'if'
p2.c:44: error: 'else' without a previous 'if'
p2.c:47: error: 'else' without a previous 'if'
p2.c:50: error: 'else' without a previous 'if'
p2.c:53: error: lvalue required as left operand of assignment

4
Contributors
3
Replies
10
Views
4 Years
Discussion Span
Last Post by scudzilla
0

Okay, I know there is a prior article about this, but I used { } with my if statements, and it's still not working... is it because I have multiple if statements consecutively after another?

No, it's because you have formatting that hides your problem. See this for proper formatting suggestions.

1

Anyway, on your problem is that for every else if statements, you added a semicolon after the condition. You are not supposed to do that. Additionally, you're missing another equal sign at line 53.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.