Home > Back-end >  [problem description] text file score. TXT mediator has a group of student performance (integer)
[problem description] text file score. TXT mediator has a group of student performance (integer)

Time:12-11

[problem description] text file score. TXT mediator has a group of student performance (as an integer), separated with a space between grades, scores the number of unknown; Request from the file to read data, calculate the average score, the highest and lowest points, will result the results output to a file. TXT, which average retain two decimal places,
[form] input
[] output form
[the] sample input hypothesis score. The data in TXT for:
60, 90, 80, 70[sample output] result. The data in TXT for: 75.00 90 60
Procedure is as follows: # include
#include
Int main ()
{
The FILE * fp, * fg;
Int a, [4].
Int I, s=0;
Int m, n;
Float c;
If ((fp=fopen (" c: \ \ score. TXT ", "r"))==NULL)
{
Printf (" the File open error! \n");
exit(0);
}
for(i=0; i<4. I++)
{
The fscanf (fp, "% d", & amp; A [I]);
S +=a, [I].
}
C=s/4.0;
M=a, [0]. N=a, [0].
for(i=0; i<4. I++)
{
If (mM=a, [I].
If (n> A [I])
N=a, [I].
}
If ((fg=fopen (" c: \ \ result. TXT ", "w"))==NULL)
{
Printf (" the File open error! \n");
exit(0);
}
Fprintf (fg, "% 2 f % d % d", c, m, n);
Printf (" % 2 f % d % d ", c, m, n);
The fclose (fp);
The fclose (fg);
return 0;
}
Ask why its output to the screen, nothing wrong?
 

CodePudding user response:

Three values should be output

CodePudding user response:

 # include & lt; stdio.h> 
#include

Int main ()
{
The FILE * fp, * fg;
Int a, [4].
Int I, s=0;
Int m, n;
Float c;
If ((fp=fopen (" c: \ \ score. TXT ", "r"))==NULL)
{
Printf (" the File open error! \n");
exit(0);
}
for(i=0; i<4. I++)
{
The fscanf (fp, "% d", & amp; A [I]);
S +=a, [I].
}
C=s/4.0;
M=a, [0]. N=a, [0].
//for (I=0; i<4. I++)
for(i=1; i<4. I++)
{
If (m
M=a, [I].
If (n> A [I])
N=a, [I].
}
If ((fg=fopen (" c: \ \ result. TXT ", "w"))==NULL)
{
Printf (" the File open error! \n");
exit(0);
}
Fprintf (fg, "% 2 f % d % d \ n", c, m, n);
Printf (" % 2 f % d % d \ n ", c, m, n);
The fclose (fp);
The fclose (fg);
return 0;
}

For your reference ~
Code not found what problem

CodePudding user response:

Results the number of unknown; So in the for loop i<4 does not conform to the question

CodePudding user response:

Thank you,
  • Related