当我尝试运行它时,我才得到这个
error: expected ‘;’, ‘,’ or ‘)’ before ‘&’ token
它在抱怨这条线
int read_values(double &sum) {
所以我想传递总和,然后直接编辑它。你如何在 C 中做到这一点?多谢你们。
#include <stdio.h>
/*
Read a set of values from the user.
Store the sum in the sum variable and return the number of values read.
*/
int read_values(double &sum) {
int values=0,input=0; double sum2=0;
sum2 = sum;
printf("Enter input values (enter 0 to finish):\n");
scanf("%d",&input);
printf("%d\n", input);
while(input != 0) {
values++;
sum2 += input;
scanf("%d",&input);
}
return values;
}
int main() {
double sum=0;
int values;
values = read_values(sum);
printf("Average: %g\n",sum/values);
return 0;
}