I'm trying to calculate the average of numbers. In order to do so, I need to get the sum of all the numbers entered. I can't figure out why I'm getting a run-time error. It's counting the number of entries correctly, but I can't get the sum to work. Please help!
Code:
void readData(float* num, float*n, float* sum);
//function main
int main ()
{
// declarations and initializations
float num=1;
float n=0;
float sum=0;
//prompts and scans
readData(&num,&n,&sum);
// calculation
// output
return 0;
}
// more functions
void readData(float*num, float*n, float* sum)
{
while (num>0)
{
printf("\nEnter a number > 0: ");
scanf("%f", &num);
*n=*n+1;
printf("Number of entries: %f\n",*n);
*sum=*sum+*num;
printf("Sum: ", *sum);
}
return;
}