Error "Syntax in function main"-thing

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • armelle22
    New Member
    • Aug 2012
    • 4

    Error "Syntax in function main"-thing

    Seriously, me and my stupid logic can't get rid of that syntax thing... My friend once fixed it but it reappeared when I ran it at my PC

    Code:
    #include<stdio.h>
    #include<conio.h>
    #include<stdlib.h>
    #include<time.h>
    
    void main()
    {
    srand(time(NULL));
    clrscr();
    int you, comp;
    randomize();comp=rand()%3+1;
    printf("Jank'n Poy");
    printf("\n[0]Scissor\n[1]Paper\n[2]Rock");
    printf("\nEnter Your choice:");
    scanf("%d",&you);
    if((you==0)&&(comp==1))
    {printf("Your Choice: Scissor");
    printf("\nOpponent: Paper");
    printf("\nYou Win!");}
    else if((you==1)&&(comp==1))
    {printf("Your Choice: Scossor");
    printf("\nOpponent: Scissor");
    printf("\n\nDraw!");}
    else if((you==2)&&(comp==1))
    {printf("Your Choice: Rock");
    printf("\nOpponent: Paper");
    printf("\n\nYou Lose!");}
    else if((you==0)&&(comp==0))
    {printf("Your Choice: Paper");
    printf("\nOpponent: Paper");
    printf("\n\nDraw!");}
    else if((you==1)&&(comp==0))
    {printf("Your Choice: Paper");
    printf("\nOpponent: Scissor");
    printf("\n\nYou Lose!");}
    else if((you==2)&&(comp==0))
    {printf("Your Choice: Rock");
    printf("\nOpponent: Scissor");
    printf("\n\nYou Win!");}
    else if((you==0)&&(comp==2))
    {printf("Your Choice: Scissor");
    printf("\nOpponent: Rock");
    printf("\n\nYou Lose!");}
    else if((you==1)&&(comp==2))
    {printf("Your Choice: Paper");
    printf("\nOpponent: Rock");
    printf("\n\nYou Win!");}
    else if((you==2)&&(comp==2))
    {printf("Your Choice: Rock");
    printf("\nOpponent: Rock");
    printf("\n\nDraw!");}
    else if(you>3)
    {printf("Invalid Input!");}
    
    getch();
    }
    Code:
    #include<stdio.h>
    #include<conio.h>
    #include<stdlib.h>
    #include<time.h>
    void main()
    {
    clrscr();
    int a, b, c, d, e,result;
    printf("Color Game");
    printf("\n[1] Yellow \n[2] Blue \n[3] Viloet \n[4] Red \n[5] Green \n[6] Orange");
    printf("\n\nBet:");
    scanf("%d",&a);
    printf("Your Color:");
    scanf("%d",b);
    c=1+random(6);
    d=1+random(6);
    e=1+random(6);
    printf("\nColors:\t%d\t\t%d\t\t%d",c,d,e);
    if((b==c)&&(b==d)&&(b==e))
    {result=a*5;
    printf("\n\n\t\tPrize:%d",result);}
    else if(!(b==c)&&(b==d)&&(b==e))
    {result=a*3;
    printf("\n\n\t\tPrize:%d",result);}
    else if((b==c)&&!(b==d)&&(b==e))
    {result=a*3;
    printf("\n\n\t\tPrize:%d",result);}
    else if((b==c)&&(b==d)&&!(b==e))
    {result=a*3;
    printf("\n\n\t\tPrize:%d",result);}
    else if(!(b==c)&&!(b==d)&&(b==e))
    {result=a*2;
    printf("\n\n\t\tPrize:%d",result);}
    else if((b==c)&&!(b==d)&&!(b==e))
    {result=a*2;
    printf("\n\n\t\tPrize:%d",result);}
    else if(!(b==c)&&(b==d)&&!(b==e))
    {result=a*2;
    printf("\n\n\t\tPrize:%d",result);}
    else if(!(b==c)&&!(b==d)&&!(b==e))
    {printf("\n\n\t\tSorry, You Lose!");}
    getch();
    }
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    It's probably right here:

    Code:
    srand(time(NULL));
    The time function returns a time_t but the srand function needs an unsigned int as an argument.

    I expect after you cnvert a time_t to an unsigned int, your code will compile.

    Comment

    • armelle22
      New Member
      • Aug 2012
      • 4

      #3
      Uhmn.. so, what statement should I add or remove to make that error disappear?

      Comment

      • divideby0
        New Member
        • May 2012
        • 131

        #4
        Code:
        srand((unsigned)time(NULL));

        Code:
        printf("Your Color:");
        scanf("%d",b); <-- &b
        you'll want to fix this one

        Code:
        #include<conio.h> non-standard header
        
        randomize()  non-standard function, I think
        clrscr() non-standard function
        the code bits above may cause problems depending on the compiler you're using.

        post the compiler warnings / errors

        Comment

        Working...