0% found this document useful (0 votes)
25 views

#Include : "Answers - TXT" "R" "%C" "%C"

This C program reads student answer data from a file, scores each answer on a test with 5 questions, tracks the minimum, maximum, and average scores, and prints the results. It initializes variables, opens the answer file, reads the correct answers key, then loops through reading each student's answers and calculating their score by awarding points for correct answers and subtracting for incorrect or blank answers. It updates running totals for minimum, maximum, and average scores through each iteration and prints the student score. After all students are scored, it calculates the final average and prints the minimum, maximum, and average scores.

Uploaded by

Mohamed Sameh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

#Include : "Answers - TXT" "R" "%C" "%C"

This C program reads student answer data from a file, scores each answer on a test with 5 questions, tracks the minimum, maximum, and average scores, and prints the results. It initializes variables, opens the answer file, reads the correct answers key, then loops through reading each student's answers and calculating their score by awarding points for correct answers and subtracting for incorrect or blank answers. It updates running totals for minimum, maximum, and average scores through each iteration and prints the student score. After all students are scored, it calculates the final average and prints the minimum, maximum, and average scores.

Uploaded by

Mohamed Sameh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

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 <stdio.h>
void main()
{
char Correct[6];
char Answer;
int Student, Mark;
int MinMark, MaxMark;
double Avg;
Student = 0;
fil = fopen("Answers.txt","r");
for(i=1;i<=5;i++)fscanf(fil,"%c",&(Correct[i]));
fscanf(fil,"%c",&Answer);
while(feof(fil))
{
Mark=0;
for(i=1;i<=5;i++)
{
fscanf(fil,"%c",Answer);
if(Answer==Correct[i])Mark +=4;
else if(Answer=='x')Mark -=1;
}
fscanf(fil,"%c",&Answer);
Avg += Mark;
if(Student==1)
MinMark = Avg;
Avg = MaxMark;
else
{
if(Mark > MaxMark)MaxMark = mark;
if(Mark > MinMark)MinMark = mark;
}
printf("Student: %lg Mark: %d\n",Student, Mark);
}
Avg/Student;
printf("Average Mark is: %lg\n",Avg);
writef("Maximum=%d Minimum=%d\n",MaxMark,MinMark);
}

You might also like