【发布时间】:2015-09-22 15:02:08
【问题描述】:
这是代码的一部分。我一直在尝试编译,但它一直给我这个错误。是不是赋值语句有问题?
ass1cpy.c:在函数“player_data”中:
ass1cpy.c:26:46:警告:变量“分数”已设置但未使用 [-Wunused-but-set-variable]
double average_goals,average_shots,effIndex,score[MAX];
int
player_data(void){
char name[MAX];
int maxgames,playerId,games,minutes,goals,shots,assists,yellowCards,
redCards,checker = 0, i = 0;
double average_goals,average_shots,effIndex,score[MAX];
scanf("%d",&maxgames);
while(scanf("%d %d %d %d %d %d %d %d %s",&playerId,&games,&minutes,&goals,&shots,
&assists,&yellowCards,&redCards,name) == 9){
average_goals = goal_average(goals,games);
average_shots = shots_average(shots,goals);
effIndex = effIndex_cal(goals,assists,redCards,yellowCards,games,maxgames);
if(checker == 0){
printf("Player %d scored %d goals in %d minutes from %d games\nGoals per"
" game: %05.2f\nShots per goal: %05.2f\nEffindex: %05.2f\n",playerId,
goals,minutes,games,average_goals,average_shots,effIndex);
}
checker = 1;
score[i] = effIndex
i++;
}
return 0;
}
如何更改它以使其可以编译?
【问题讨论】:
-
看起来很明显:“警告:变量'score'设置但未使用”
-
不,它只是告诉你不要使用
score做任何事情。 -
编译器会看到您将数据添加到
score数组。它的问题在于您的代码没有使用您添加的数据。 -
它确实编译(除非你没有告诉我们其他事情)。如果你想要一个无警告的编译——为什么不使用分数呢?
-
score[i] = effIndex缺少;并且以后从未使用过