创建变化的变量

时间:2016-10-04 13:13:58

标签: c loops variables c99

这是我的代码的一部分:

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等中。

1 个答案:

答案 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);
    }
}