trying to read input into an array
i am reading input into an array froman input file. it's reading the numbers but not the right ones. this is my code for filling the array
Code:
void fill_arr(float farry[], int *sizearr){
int fills = 0;
while (fills < *size && scanf(“%f”, &farry[fills]) !=EOF)
fills ++;
}
*sizearr = fills;
}
then i call the add function tha i wrote
Code:
float add_arr(float adarry[], int sizearr){
int count;
float sum = adarry[0];
for(count = 1; count < sizearr; count++){
sum += adarry[count];
}
return sum;
}
and its not doing that correctly. i keep getting zero as the result
sorry was copy/pasting from word thts why " were slanted. they are straight in code
oh ok!!! i see. sorry beginner here. ok so now that that works. the printing part is not coming out right.
Code:
printf("choice = %c: result = %.3f\n",menuChoice,result);
/* code to print the number of operands given and list them
in the same order they were given on the next line */
for(counted = 0; counted < sizearr; counted++){
numoperands++;
}
printf("There were %d operands given\n", numoperands);
for(counted =0; counted < sizearr; counted++){
printf("%.3f ",countarr[counted]);
}
}
printf("\n");