Hello am new in the game and am somehow stuck, I cant get the "avgScore" and the "ctr" right. can someone pliz tell me where am going wrong.
Code:
int IdNum,J1,J2,J3,ctr,e;
float totalScore,avgScore,total;
FILE *payInFile, *payOutFile;
payInFile=fopen("dataIn.txt","r");
payOutFile=fopen("dataOut.txt","w");
fprintf(payOutFile,"\n Candidate Results\n");
fprintf(payOutFile,"IdNum J1 J2 J3 totalScore \n");
ctr=0;
total=0;
e=fscanf(payInFile, "%1d %1d %1d %1d", &IdNum, &J1, &J2, &J3);
while(e==5)
{
totalScore = J1+J2+J3;
fprintf(payOutFile,"%d %d %d %d %3.1f\n",
IdNum ,J1 ,J2 ,J3 ,totalScore);
ctr=ctr+1;
total = total + totalScore;
e=fscanf(payInFile, "%1d %1d %1d %1d", &IdNum, &J1, &J2, &J3);
}
avgScore = totalScore / ctr;
fprintf(payOutFile, "ctr = %2f and avgScore is %2.2f \n",ctr,avgScore);
fclose(payInFile);
fclose(payOutFile);
system("pause");
} //end program
You can use this Data
IdNum J1 J2 J3
6 3 2 4
5 2 3 3
4 5 2 4
3 4 5 4
2 3 2 3
1 2 3 2