这是我的代码的一部分:
float score_from_judge(number_judges, n)
{
float judge_score;
printf("Score from judge %d? ", n);
scanf("%f", &judge_score);
return(judge_score);
}
int main(void)
{
int n;
float judge_score;
n=1;
for(n; n<=number_judges; n++ ) {
judge_score = score_from_judge(number_judges, n)
}
}
我正在寻找一种方法,每当score_from_judge返回值时,在一个变量中保存jud_score。 我试图找到一种方法为每个循环创建一个新变量。
例如,我第一次收到judge_score,它会保存在variable_1中,下次会保存在variable_2等中。
答案 0 :(得分:0)
声明一个float数组并将其值设置在&#39; for&#39;循环,如图所示:
int main(){
float judge_score[10];
for(int n=1; n<=number_judges; n++ ) {
judge_score[n] = score_from_judge(number_judges, n);
}
}