I was able to finish it, by the way. I had to rewrite somethings and dumb it down a bit so it can look like I did it lol. I think it looks pretty different though and also there were problems calculating the sum of the last 2 columns and the average of them as well, but over all it wasn't much to fix.
This was my final code incase anyone was interested.
#include <stdio.h>
/* Introduction to Computer Science CSEN 2304
* Assignment 3
* Due Tuesday, November 20
*/
main()
{
double input[9][3] ={ {-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} };
FILE *outp;
int i, j;
double rowSums[9] = {0.0};
double columnSums[3] = {0.0};
double sum,avg;
outp = fopen("result.out", "w");
/* Draws the heading */
printf(" ");
fprintf(outp, " ");
for (i = 0; i < 3; i++)
{
printf(" ");
fprintf(outp, " ");
printf("#%d ", i);
fprintf(outp, "%d ", i);
}
printf(" Sum Average\n");
fprintf(outp, " Sum Average\n");
lines();
/* Loop to calculate */
for (i = 0; i < 9; i++)
{
printf("%2d", i + 1); // Shows current row
fprintf(outp, "%2d", i + 1);
for (j = 0; j < 3; j++)
{
rowSums[i] += input[i][j];
columnSums[j] += input[i][j];
printf(" %9f", input[i][j]); //Shows the inputs
fprintf(outp, " %9f", input[i][j]);
}
printf(" %9f %9f", rowSums[i], rowSums[i] / 3);
fprintf(outp, " %9f %9f", rowSums[i], rowSums[i] / 3);
sum += rowSums[i];
avg += rowSums[i] / 3;
printf("\n");
fprintf(outp, "\n");
}
lines();
printf("sum");
fprintf(outp, "sum");
for (i = 0; i < 3; i++)
{
printf(" %9f ", columnSums[i]);
fprintf(outp, " %9f ", columnSums[i]);
}
/* Prints the sum row */
printf(" %9f ", sum);
fprintf(outp, " %9f ", sum);
printf(" %9f", avg);
fprintf(outp, " %9f", avg);
printf("\n");
fprintf(outp, "\n");
lines();
printf("avg.");
fprintf(outp, "avg.");
for (i = 0; i < 3; i++)
{
printf(" %9f ", columnSums[i] / 9);
fprintf(outp, " %9f ", columnSums[i] / 9);
}
printf(" %9f ", sum / 9);
fprintf(outp, " %9f ", sum / 9);
printf(" %9f\n\n", avg / 9);
fprintf(outp, " %9f\n\n", avg / 9);
system("PAUSE");
}
lines(int i) {
FILE *outp;
outp = fopen("result.out", "w");
printf(" ");
fprintf(outp, " ");
for (i=0; i <=4; i++)
{
printf("--------- ");
fprintf(outp, "--------- ");
}
printf("\n");
fprintf(outp, "\n");
}
If you actually run it, you'll notice that the .exe runs perfectly, but the file that is written doesn't. I'm not to sure why this happened, but it did. I wasn't able to fix it before I went to my chem study session for the night.