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
|
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#define FILENAME "suture.txt"
main()
{
int numdata=0, temp_fail=0, press_fail=0, dwell_fail=0, batchnum=0;
float temp, press, dwell;
FILE *infile;
FILE *outfile;
outfile = fopen("Lynch_outfile.txt","w");
infile = fopen(FILENAME, "r");
if(infile == NULL)
printf("Error opening input file.");
else
{
while((fscanf(infile,"%lf %lf %lf %lf",&batchnum, &temp, &press, &dwell)==4))
{
if(temp<150 || temp>170)
temp_fail++;
if(press<60 || press>70)
press_fail++;
if(dwell<2 || dwell>2.5)
dwell_fail++;
numdata++;
}
fprintf(outfile,"Total defective batches: %i\n", numdata);
fprintf(outfile,"Defective due to temperature: %.3f (%.2f %)\n", temp_fail, (temp_fail/numdata)*100);
fprintf(outfile,"Defective due to pressure: %.3f (%.2f %)\n", press_fail, (press_fail/numdata)*100);
fprintf(outfile,"Defective due to dwell time: %.3f (%.2f %)\n", dwell_fail, (dwell_fail/numdata)*100);
fclose(infile);
fclose(outfile);
}
getch();
return 0;
}
|