首页 文章

得到错误:预期的标识符或'('''''令牌之前[关闭]

提问于
浏览
0

int main 之前的 #include 之后的第一个方括号上出现此错误: expected identifier or ‘(’ before ‘{’ token . 不知道为什么!为入门编程课程做作业 . 它今天到期,所以任何帮助将不胜感激!

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
{
int main(void);

int cardNum(int firstCard, int secondCard; 
int highLow;
int score;

score = 0;   
srand(time(NULL));

    printf("The current card is a %d\n" ,firstCard(2,14));
    printf("\n Will the next card be higher(1) or lower(2)? (press 0 to quit)");
    scanf("%d" ,highLow);
if cardNum > 1 && cardNum < 11
{        
     printf ("The card is: %d ,secondCard.");
}        
else if cardNum == 11
{
if highLow == 1, && secondCard > firstCard OR highLow == 2, && secondCard < firstCard
    {   
        score = score + 1; 
        printf ("\n You have guessed correctly.");
        printf ("\n Your current score is %d ,score!\n");
        printf("The current card is a ("%d" ,cardOne). \n Will the next card be           higher(1) or lower(2)? (press 0 to quit)");
    }    
else if highLow == 1, && secondCard < firstCard OR highLow == 2, && secondCard > firstCard  
    {
        score = score - 1;
        printf ("The card is: %d ,secondCard.");
        printf ("\n You have guessed incorrectly.");
        printf ("\n Your current score is %d ,score!\n");
        printf ("The current card is a %d ,cardOne."); 
        printf ("\n Will the next card be higher(1) or lower(2)? (press 0 to quit)");
    }
else if secondCard == firstCard
    {
        printf ("\n Matching cards, no change in score");
    }
else if highLow == 0
    {
        printf ("\n Thanks for playing! Your final score is %d, score.");
    }
else
    {
        printf ("\n Incorrect input. Please enter 0, 1 or 2")       
    }
}    
return(0);
}

我最初使用int main(void){但后来我得到了所有这些错误,所以我把它改成了分号,只得到了一个错误 .
a3.c:在函数'main'中:a3.c:24:5:错误:预期声明说明符或'得分'之前的'...'a3.c:25:5:错误:预期声明说明符或'.. ''之前'srand'a3.c:27:5:错误:预期的声明说明符或'...'在'printf'之前a3.c:28:5:错误:预期的声明说明符或'...'之前' printf'a3.c:29:5:错误:在'scanf'之前的预期声明说明符或'...'a3.c:31:5:错误:预期声明说明符或'if'a3之前的'...' . c:82:1:错误:预期的声明说明符或'}'之前'}'令牌a3.c:82:1:错误:预期';',','或')''}''''令牌a3 .c:82:1:错误:输入结束时的预期声明或语句a3.c:82:1:警告:控制到达非void函数的结尾[-Wreturn-type]

2 回答

  • 7
    {
    int main(void);
    

    应该

    int main(void)
    {
    

    然后我让你修复程序的下一个编译错误......

  • 4

    你需要在 main 之后放置左大括号,而不是在它之前

    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    
    int main(void)
    {
    

相关问题