我正在写一个计算足球比赛结果的程序。我试图将队ids'存储在顶部定义长度为10的数组中,但是我一直从数组中获取构建错误。我意识到语法可能是错误的,但我还可以如何使用变量来指定数组长度? 我收到的错误消息是:'{'标记之前的预期表达式。我如何将数组存储在C中?
#include <stdio.h>
#include <stdlib.h>
#define ARRAY_SIZE 10
int main() {
int numberofmatches, hometeamid, awayteamid, hometeamgoals, awayteamgoals;
int hometeamwins = 0;
int winratio;
int teamid[ARRAY_SIZE];
printf("Enter number of matches played \n");
scanf("%d", &numberofmatches);
if (numberofmatches > 0) {
int x = 0;
do {
printf("Enter match stats in order Home_team_ID,Away_Team_ID,Goals_Home,Goals_Away\n");
scanf("%d %d %d %d", &hometeamid, &awayteamid, &hometeamgoals, &awayteamgoals);
teamid[ARRAY_SIZE] = {hometeamid}; //Error is on this line
if (hometeamgoals > awayteamgoals) {
hometeamwins++;
}
x++;
}
while (x < numberofmatches);
winratio = hometeamwins/numberofmatches;
printf(" %d :teamidth %d :winratio", teamid[0], winratio);
}
return 0;
}
您是否尝试阅读错误? – SLaks
错误说的是什么?它是数组还是你的while循环? –
你觉得'teamid [ARRAY_SIZE] = {hometeamid};'是在你的循环中进行的吗? – Yunnosch