Im at my wits end, please help
I am currently working on program for a class that is tearing me a new one. Its a gnu c program that calculates fica tax rates, gross, uses page breaks, and is compiled using make file. I have the overall structure down, I am just having some random errors when I go to run the Makefile. I just need a bit of guidance in the right direction, and I am not asking anyone to do this for me. Here are my files so far.
Here is my main, Lab2.c
Code:
#include <stdio.h>
#include <stdlib.h>//exit method
#include <string.h>
#include "calGross.c"
#include "calFica.c"
#include "newPage.c"
int main(){
//start variable declarations//
FILE *outFile, *inFile;
float hrs[20],pyRt[20],ficaTax[20], YTD[20], gross[20], net[20],Pgross,Pfica,Pnet, Rgross, Rfica, Rnet;
int empNum[20],pgKt, lnKt, mxLn;
char outputName[21], inputName[21], firstName[20][15], lastName[20][20],dep[20][6],ans ;
//end variable declerations//
//begin input file//
printf("\n\n\nEnter the name of input file[max 20 characters]: ");
scanf("%s", &inputName);
inFile=fopen(inputName,"r");
if(inFile==NULL){
printf("Input file does not exist, program terminating.");
exit(1);}
//end input file//
//begin output file//
printf("\n\n\nEnter the name of file to hold the results[max 20 characters]: ");
scanf("%s",&outputName);
if((outFile=fopen(outputName,"r"))!=NULL){
printf("\n\n %s exists, do you want to overwrite existing file?(y or n): ",outputName);
scanf("%*c%c",&ans);//input resp, skips 1 character in buffer(<cr>)
if((ans=='n')||(ans=='N')){printf("\nProgram aborted to prevent overwrite!");exit(1);}}
outFile=fopen(outputName,"w");//opens/overwrites file if answer was not 'n'||'N'
if(outFile==NULL){printf("\nCould not create file, program aborted!");exit(1);}
//end output file//
//begin header page//
fprintf(outFile,"%27s","AMCE Inc.");
fprintf(outFile,"\n%19s", "We are the best, you use the best!");
//end header page//
//Begin Total definitions
pgKt=1;
lnKt=0;
mxLn=20;
Pgross=0;
Pfica=0;
Pnet=0;
Rgross=0;
Rfica=0;
Rnet=0;
//End Total definitions
//Begin Read Data
int a=0;//counter for read data loop
while((fscanf(inFile,"%i",&empNum[a]))!=EOF){
fscanf(inFile,"%c%c%c%f%f%f%f",&firstName[a],&lastName[a],
&dep[a],&YTD[a],&pyRt[a],&hrs[a]);
a++;}
//End Read Data
//begin calculate Payroll
int b=a;
a=0;
while(a<=b){
if( lnKt=mxLn){
newPg(pgKt,lnKt,Pgross,Pfica,Pnet,Rgross,Rfica,Rnet,outFile);}//new page
grossCalc(a, pyRt,hrs, gross);
ficaCalc(a,ficaTax,gross,YTD);
fprintf(outFile,"%2i%-10s%-10s%10.2f%10.2f%10.2f%10.2f\n",empNum[a],firstName[a],lastName[a],YTD[a],gross[a],ficaTax[a],net[a]);}//end print ln
lnKt++;
Pgross=Pgross+gross[a];
Pfica=Pfica+ficaTax[a];
Pnet=Pnet+net[a];
a++;}
//end calculate Payroll
//begin closing
pgKt++;
fprintf(outFile,"\n%24s","Report Summary");
fprintf(outFile,"\n\n%s%i","Records Processed: ",b);
fprintf(outFile,"\n%s%f","\nTotal Gross: $",Rgross);
fprintf(outFile,"\n%s%f","\nTotal Net : $",Rnet);
fprintf(outFile,"\n%s%f","\nTotal FICA : $",Rfica);
fprintf(outFile,"%s%i","Page ",pgKt);
fclose(inFile);
fclose(outFile);
//end closing
return 0;
}
Here is newPage.c
Code:
float nwPage(int x,int y,float c,float d ,float e,float f, float g, float h, FILE *filename){
//begin last page
fprintf(filename,"\n\n%-25s%10.2f%10.2f%10.2f","Page Totals:",c,d,e);
fprintf(filename,"\n%s%i","Page ",x);
f=f+c;
g=g+d;
h=h+e;
//end last page
//begin new page
x++;
fprintf(filename,"\n\n%s%s%s%s%s%s%s","Emp#","Name","Dept.","New YTD","Gross","FICA","Net");
y=0;
c=0;
d=0;
e=0;
//end new page
return x,y,c,d,e,f,g,h;
}
Here is calGross.c
Code:
float grossCalc(int k,float i[], float j[], float l[]){
if(j[k]<=40){
l[k]=i[k]*j[k];}//pay normal rate
else if (j[k]>40){
i[k]=(i[k]*1.5);//change payrate for overtime
l[k]=i[k]*j[k];}
return l[k];//return gross
}
Here is calFica.c
Code:
//begin ficaCalc function
float ficaCalc(int p,float m[],float n[],float o[]){//fica calculations function
float ficaLimit=(102,000);
float ficaRate=(6.2);
float v1= (o[p] + n[p]);//sets v1 to the sum of YTD & gross for an easily checkable value
if (v1 <= ficaLimit){m[p] = (n[p] * ficaRate);}
else if((v1>ficaLimit)&&(o[p]<ficaLimit)){m[p] = ((ficaLimit - o[p])*ficaRate);}
else if (o[p] > ficaLimit){m[p] = 0;}
v1=0;
return m[p];}
//end ficaCalc function
and here is the MakeFile
Code:
Lab: Lab2.o calGross.o calFica.o newPage.o
gcc -o Lab Lab2.o calGross.o calFica.o newPage.o
Lab2.o: Lab2.c
gcc -o Lab2.o Lab2.c
calGross.o: calGross.c
gcc -o calGross.o calGross.c
calFica.o: calFica.c
gcc -o calFica.o calFica.c
newPage.o: newPage.c
gcc -o newPage.o newPage.c
and here is a list of errors that I get when I run make
Code:
Lab2.c:98: error: expected =, ,, ;, asm or __attribute__ before ++ token
Lab2.c:99: error: expected ) before string constant
Lab2.c:100: error: expected ) before string constant
Lab2.c:101: error: expected ) before string constant
Lab2.c:102: error: expected ) before string constant
Lab2.c:103: error: expected ) before string constant
Lab2.c:104: error: expected ) before string constant
Lab2.c:105: warning: data definition has no type or storage class
Lab2.c:105: warning: parameter names (without types) in function declaration
Lab2.c:106: warning: data definition has no type or storage class
Lab2.c:106: warning: parameter names (without types) in function declaration
Lab2.c:108: error: expected identifier or ( before return
Lab2.c:109: error: expected identifier or ( before } token
make: *** [Lab2.o] Error 1
Now I have narrowed down the problem to the newPage.c, as when I comment the function and compile, these go away and are replaced with some even nastier ones, that appear to come from calGross.c. I believe the newPage.c errors have to do with me passing the output file through the function parameters, but I know of no other way to do this. Any help will be much appreciated.