Nov 12, 2013 at 7:58pm UTC
I am trying to write a C program to take numbers from an input file (input.dat), calculate the sum and average of the numbers for each row, and display them in a form of table and in an output file (result.out).
Using these numbers in the input file.
-0.043200 -0.003471 0.000000
-0.040326 -0.004851 -0.000737
-0.018204 -0.004246 -0.001530
0.022249 0.008891 0.004870
0.074892 0.044237 0.032171
0.129600 0.100233 0.089016
0.174747 0.160100 0.161792
0.200242 0.199106 0.214417
0.174747 0.160100 0.161792
i have created the the file but i keep getting errors in the underlined area after the while!!!
Your help is greatly appreciated
#include <stdio.h>
int
main(void)
{
double sum; /*Sum of all numbers*/
double average; /*Average of all numbers*/
double first, second, third;
int line;
printf("Assignment 6\n");
printf("Rodolfo Esparza\n");
printf("K00326334\n\n");
FILE *inp, /*input file*/
*outp; /*output file*/
/*Open Files*/
inp = fopen("input.dat", "r");
outp = fopen("output.out", "w");
line = 0;
while (line <= 9) {
fscanf (inp, "%lf%lf%lf", &first, &second, &third);
fprintf (outp, "%lf%lf%lf", &first, &second, &third);
line++
}
sum = first+second+third //Formula for sum
average = first+second+third/3 //Formula for average
/*close Files*/
fclose(inp);
fclose(outp);
return 0;
}
Nov 12, 2013 at 8:13pm UTC
You're missing some semicolons near the closing brace for the while loop.
-Albatross