I am trying to load a 3x8 array of doubles but my code keeps outputting 0.00 for all of the values. The code should be outputting the array (same as the input) under the Read#1 Read#2 Read#3 lines, with the average under average.
Here is my code:
#include <stdio.h>
double getAvg(double num1, double num2, double num3);
int main()
{
int numJ,month,day,year,i,j;
double arr[3][8];
scanf("%d %d %d %d",&numJ,&month,&day,&year);
for (i = 0; i < 8; i++)
{
scanf("%f %f %f",&arr[i][0], &arr[i][1], &arr[i][2]);
}
printf("\nJob %d Date: %d/%d/%d",numJ,month,day,year);
printf("\n\nLocation Read#1 Read#2 Read#3 Average");
for (j = 0; j < 8; j++)
{
printf("\n %d %.2f %.2f %.2f %.2f",j+1,arr[j][0],arr[j] [1],arr[j][2],getAvg(arr[j][0],arr[j][1],arr[j][2]));
}
return 0;
}
double getAvg(double num1, double num2, double num3)
{
double avg = (num1 + num2 + num3) / 3;
return avg;
}
Input example:
157932 09 01 2013
0.00 0.00 0.00
0.36 0.27 0.23
0.18 0.16 0.26
0.27 0.00 0.34
0.24 0.00 0.31
0.16 0.33 0.36
0.29 0.36 0.00
0.21 0.36 0.00