This is the problem, when I run it, there are no errors. However when I check the reportfile, I end up with the wrong numbers from the calculations.

The calculator:

void  AddDetailToAccumulators(float *totfedtax, float *totssitax, float *totstatetax,float *totrate, float *totreg,
			 float *totovt, float *totgross,float *totpay,float *totdeferred, float gross, float federaltax, float statetax,
			float ssitax,float hours, float payrate,float deferred,float reghrs,float ovthrs,float netpay,float *avgfedtax, float *avgssitax, float *avgstatetax,float *avgrate, float *avgreg,
			 float *avgovt, float *avggross,float *avgpay,float *avgdeferred)
{
	*totfedtax+=federaltax;
	*totstatetax+=statetax;
	*totssitax+=ssitax;
	*totrate+=payrate;
	*totdeferred+=deferred;
	*totreg+=reghrs;
	*totovt+=ovthrs;
	*totgross+=gross;
	*totpay+=netpay;
	*avgfedtax=*totfedtax/MAX;
	*avgstatetax=*totstatetax/MAX;
	*avgssitax=*totssitax/MAX;
	*avgrate=*totrate/MAX;
	*avgdeferred=*totdeferred/MAX;
	*avgreg=*totreg/MAX;
	*avgovt=*totovt/MAX;
	*avggross=*totgross/MAX;
	*avgpay=*totpay/MAX;
}

The printer file

void  Print_Summary_To_File(float totfedtax, float totssitax, float totstatetax,float totrate, float totreg,
			 float totovt, float totgross,float totpay,float totdeferred,float avgfedtax, float avgssitax, 
			 float avgstatetax,float avgrate, float avgreg,
			 float avgovt, float avggross,float avgpay,float avgdeferred,FILE *reportfile)
{
   fprintf(reportfile, "%16s%15.2f%9.2f%9.2f%9.2f",
	  "Totals", totrate, totreg, totgross, totfedtax);
   fprintf(reportfile, "%8.2f%9.2f          \n%40.2f%18.2f%8.2f\n\n",
      totssitax, totpay, totovt,totstatetax, totdeferred);
   fprintf(reportfile, "%18s%13.2f%9.2f%9.2f%9.2f",
      "Averages", avgrate, avgreg, avggross, avgfedtax);
   fprintf(reportfile, "%8.2f%9.2f          \n%40.2f%18.2f%8.2f\n\n\n\n\n\n",
	  avgssitax, avgpay, avgovt, avgstatetax, avgdeferred);
}

What was printed on reportfile:

Employee Pay Reg Hrs Gross Fed SSI Net
Name Rate Ovt Hrs Pay State Defr Pay
================= ===== ======= ======= ======= ====== ======
Doe, John 17.00 40.00 845.75 119.36 61.67 606.36
6.50 8.36 50.00

Whittle, Ed 11.50 25.50 293.25 43.99 22.73 223.46
0.00 3.08 0.00

Marion, Louise 13.00 40.00 520.00 63.00 32.55 320.04
0.00 4.41 100.00

Prentiss, Paula 15.75 40.00 878.06 112.96 58.36 573.83
10.50 7.91 125.00

Davidson, Carl 8.75 38.00 332.50 47.63 24.61 241.93
0.00 3.33 15.00

Totals -107374112.00-107373992.00-107371296.00-107373792.00-107373976.00-107372208.00
-107374160.00 -107374152.00-107373888.00

Averages -21474822.00-21474798.00-21474260.00-21474758.00-21474796.00-21474442.00
-21474832.00 -21474830.00-21474778.00

The 'Totals' and 'Averages' section are completely out of whack. I'm guessing is a Print_Summary_To_File problem.

Well, you could look at the values in the debugger if you have one, or you could add additional print statements to better confirm the values. If you come to the conclusion that the values are correct then you have to chase back to where they came from to see where they were last correct.

(This is why developing and testing iteratively makes so much sense, you only have to look at the new stuff if something stops working.)

it almost doesn't make any sense to calculate the average as you go along (unless you need intermediate averages).

In the AddDetailToAccumulators() you are dividing the total by MAX to generate the average. Are you always going to read MAX values?

Secondarily, the AddDetailToAccumulators() adds to the totals...did you ensure that you initialized the totals to zero before you started?

I am posting this, absolutely not to find error in your code(coz its really hard to understant your code) but to tell you, how you can improve your coding style so that the error rate becomes less.

You have been suggested to use struct in place of passing so many parameters to a function.

Try to code simple so that others can understand your code easily.

At least you do this, to make ur and our life easier.

This article has been dead for over six months. Start a new discussion instead.