Need Help. Program won't run.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#include <stdio.h> 
#include <stdlib.h>
#include <string.h>
#define ADDR(var) &var
#define REPHEAD1 "     Employee     Pay       Reg Hrs     Gross       Fed      SSI     Net\n"
#define REPHEAD2 "     Name         Rate      Ovt Hrs     Pay         State    Defr    Pay\n"
#define REPHEAD3 "     ========     =====     =======     =====       =====    =====   =====\n"
#define REPFORMTa "    %-13s%5.2f%12.2f%10.2f%12.2f%9.2f%8.2f\n"
#define REPFORMTb "                  %30.2f%22.2f%9.2f\n"
#include <TAXRATES.h>

void PrintReportHeadings(FILE * reportfile); //3.1
void InitializeAccumulators(float * totpayrate, float * totreg, 
                            float * totovt, float * totgross, 
                            float * totfed, float * totstate, 
                            float * totssi, float * totdefr, 
                            float * totnet); //3.2
void InputEmployeeData (char fullname[30+1], char lastname[20+1], char firstname[10+1], float * hours, float * payrate, float * defr); //3.3
float CalculateGross(float hours, float payrate);//3.4
void CalculateTaxes(float gross,float defr,
		    float * fedtax,float *statetax,float *ssitax); // 3.5
		    void CalculateTaxes(float gross,float defr,
		    float * fedtax,float *statetax,float *ssitax); // 3.5
float CalculateFedTax(float gross, float defr); // 3.5.1
float CalculateStateTax(float fedtax); // 3.5.2
float CalculateSSITax(float gross, float defr); // 3.5.3
void AddDetailsToAccumulators(float payrate, float hours,
                            float ovthours, float gross,
                            float fedtax, float statetax,
                            float ssitax, float defr,
                            float net, float * totpayrate, float * totreg, 
                            float * totovt, float * totgross, 
                            float * totfed, float * totstate, 
                            float * totssi, float * totdefr, 
                            float * totnet); //3.6
void PrintSummaryReport(float  totpayrate, float  totreg, 
                            float  totovt, float  totgross, 
                            float  totfed, float  totstate, 
                            float  totssi, float  totdefr, 
                            float  totnet, int empCount,
                            FILE * reportfile); //3.7
int main(void)
{
    FILE * reportfile;
PrintReportHeadings(reportfile);
float totpayrate, totreg, 
      totovt, totgross, 
      totfed, totstate, 
      totssi, totdefr, totnet;
float hours, ovthours, payrate, defr, gross, net, 
      fedtax, statetax, ssitax;
char fullname[30+1], lastname[20+1], firstname[10+1], answer;
int empCount;
empCount = 0;

InitializeAccumulators(&totpayrate, &totreg, &totovt, &totgross, 
                       &totfed, &totstate, &totssi, &totdefr, &totnet);

do
{
	InputEmployeeData (fullname, lastname, firstname, &hours, &payrate, &defr);
	gross = CalculateGross(hours, payrate);
	CalculateTaxes(gross,defr,&fedtax,&statetax,&ssitax);
	net = gross - fedtax + statetax + ssitax;
	fprintf(reportfile,REPFORMTa,fullname,lastname,firstname,payrate,hours,gross,fedtax, ssitax,net);
	fprintf(reportfile,REPFORMTb,ovthours, statetax, defr);
	empCount =+ 1;
	AddDetailsToAccumulators(payrate,hours,
                         ovthours, gross,
                         fedtax, statetax,
                         ssitax, defr,
                         net, &totpayrate, &totreg, 
                         &totovt, &totgross, 
                         &totfed, &totstate, 
                         &totssi, &totdefr, 
                         &totnet);
	fprintf(reportfile,REPFORMTa,fullname,payrate,hours,gross,fedtax, ssitax,net);
	fprintf(reportfile,REPFORMTb,ovthours, statetax, defr);
	fflush(stdin);
	printf("Repeat (Y/N)? : ");
	scanf("%c",ADDR(answer));	
		}while (answer == 'Y' || answer == 'y');

PrintSummaryReport(totpayrate, totreg, 
                   totovt,  totgross, 
                   totfed, totstate, 
                   totssi, totdefr, 
                   totnet, empCount,
                   reportfile);
printf("\n");
printf(" You processed %2d employees\n",empCount);
while (getchar() != '\n');
fclose(reportfile);
return 0;
}

void PrintReportHeadings(FILE * reportfile)
{
    
	reportfile = fopen("C:\\Users\\Pow Vang\\Desktop\\report.txt","wt");
	if (reportfile == NULL)
	{
	   printf("Report file open failed ...\n");
	   fflush(stdin);
       getchar();
	   exit(-100); // reqs <stdlib.h>
	}
	fprintf(stdout,REPHEAD1); // print column heads ..
	printf(REPHEAD2);
	fprintf(stdout,REPHEAD3);
	
	fprintf(reportfile,REPHEAD1); // print column heads ..
	fprintf(reportfile,REPHEAD2);
	fprintf(reportfile,REPHEAD3);
}

void InitializeAccumulators(float * totpayrate, float * totreg, float * totovt, float * totgross, 
                            float * totfed, float * totstate, float * totssi, float * totdefr, float * totnet)
{
 totpayrate = totreg = totovt = totgross = totfed = totstate = totssi = totdefr = totnet = 0;     
}

void InputEmployeeData (char fullname[30+1], char lastname[20+1], char firstname[10+1], float * hours, float * payrate, float * defr)
{
     printf("Enter employee's last name: "); 
     scanf("%s",lastname);
     printf("Enter employee's first name: ");  
     scanf("%s",firstname);
     printf("Enter hourly pay rate: ");
     scanf("%f",ADDR(payrate));
     printf("Enter hours worked this pay period: ");
     scanf("%f",ADDR(hours));
     printf("Enter deferred amount: ");
     scanf("%f",ADDR(defr));   
     strcpy(fullname,lastname);
     strcat(fullname,", ");
     strcat(fullname,firstname);
}

float CalculateGross(float hours, float payrate)
{
if (hours <= 40)
    hours * payrate;
else
    payrate * 40 + (hours - 40) * 1.5 * payrate;
}
void CalculateTaxes(float gross,float defr,
		    float * fedtax,float *statetax,float *ssitax) // 3.5
{
    *fedtax = CalculateFedTax(gross,defr); // call 3.5.1
    *statetax = CalculateStateTax(*fedtax); // call 3.5.2
    *ssitax = CalculateSSITax(gross,defr); // call 3.5.3
}
float CalculateFedTax(float gross, float defr) // 3.5.1
{
	return (gross-defr) * FEDTAXRATE;
}
float CalculateStateTax(float fedtax) // 3.5.2
{
	return fedtax * STATETAXRATE;
}
float CalculateSSITax(float gross, float defr) // 3.5.3
{
	return (gross-defr) * SSITAXRATE;
}



void AddDetailsToAccumulators(float payrate, float hours,
                            float ovthours, float gross,
                            float fedtax, float statetax,
                            float ssitax, float defr,
                            float net, float * totpayrate, float * totreg, 
                            float * totovt, float * totgross, 
                            float * totfed, float * totstate, 
                            float * totssi, float * totdefr, 
                            float * totnet)
{
*totpayrate += payrate;
*totreg += hours;
*totovt += ovthours;
*totgross += gross;
*totfed += fedtax;
*totstate += statetax;
*totssi += ssitax;
*totdefr += defr;
*totnet += net;
}

void PrintSummaryReport(float  totpayrate, float  totreg, 
                            float  totovt, float  totgross, 
                            float  totfed, float  totstate, 
                            float  totssi, float  totdefr, 
                            float  totnet, int empCount,
                            FILE * reportfile)
{
  fprintf(reportfile,"\n");
  fprintf(reportfile,REPFORMTa,"Totals", totpayrate, totreg, totgross, totfed, totssi, totnet);
  fprintf(reportfile,REPFORMTb, totovt, totstate, totdefr);
  fprintf(reportfile,REPFORMTa,"Averages",totpayrate/empCount,
                                          totreg/empCount,
                                          totgross/empCount,
                                          totfed/empCount,
                                          totssi/empCount,
                                          totnet/empCount);                            
  fprintf(reportfile,REPFORMTb,totovt/empCount,
                               totstate/empCount,
                               totdefr/empCount);
}


I need some help, I know that I did something wrong but I just don't know where. The syntax is all correct, but when I run it, it crashes after I enter the data inputs.
Wow, I think we're in the same class. Which reminds me that I need to finish the re-work of this ASAP since it's due in an hour.

I suggest you try figuring out what's going wrong by outputting a message to the console at the beginning of each function, to figure out where exactly the program is crashing.
The furthest I got to was the data input from the InputEmployeeData function, after that it freezes up.
Just because it freezes up right there doesn't mean that there's a problem with the input function. You might have an error somewhere else in another function, which prevents you from completing the loop and asking for input again.

Now that I look at it, your CalculateGross function does not have a return. That could be the problem.
Thanks for the help fg109. I figured it out, it wasn't the CalculateGross function. I corrected it by removing the variable fullname.
Topic archived. No new replies allowed.