tobblitz tobblitz - 1 year ago 70
C Question

creating variable that change

This is part of my code:

float score_from_judge(number_judges, n)
float judge_score;
printf("Score from judge %d? ", n);
scanf("%f", &judge_score);


int main(void)
int n;
float judge_score;
for(n; n<=number_judges; n++ ) {
judge_score = score_from_judge(number_judges, n)

I am looking for a way to save judge_score in a variable every time score_from_judge returns the value.
I am trying to find a way to make a new variable for each loop.

For example, first time I recieve judge_score it is saved in variable_1 and next time in variable_2 etc.

Answer Source

declare a float array and set its value inside the 'for' loop, as shown:

int main(){
    float judge_score[10];
    for(int n=1; n<=number_judges; n++ ) {
        judge_score[n] = score_from_judge(number_judges, n);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download