I just get this when I try to run it
error: expected ‘;’, ‘,’ or ‘)’ before ‘&’ token
it's complaining about this line
int read_values(double &sum) {
so i want to pass sum, and then edit it directly. How do you do that in C? Thanks guys.
#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;
}