This repository has been archived by the owner on Jun 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
student_result.c
134 lines (113 loc) · 2.79 KB
/
student_result.c
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct student //making student structure
{
char name[50];
int class;
int science;
int maths;
int computer;
float average;
char grade;
};
char grading(float mark){
char grad;
if (mark>90){
grad='O';
}
else if (mark>80)
{
grad='A';
}
else if (mark>70)
{
grad='B';
}
else if (mark>60)
{
grad='C';
}
else if (mark>50)
{
grad='D';
}
else if (mark>40)
{
grad='E';
}
else{
grad='F';
}
return grad;
}
int legitMarkChecker(){
int mark;
while(1){
scanf("%d",&mark);
if(mark<=100 && mark>0){
break;
}
else
{
printf("-----INVALID INPUT-----\n");
printf("Enter the mark again:");
}
}
return mark;
}
int main(void){
int maxstud,class;
float avgmark;
char maxstudstr[sizeof(int)],classstr[sizeof(int)];
printf("Enter the no of students:");
fgets(maxstudstr,sizeof(int),stdin);
maxstud=atoi(maxstudstr);
struct student stud[maxstud];
printf("Which class:");
fgets(classstr,sizeof(int),stdin);
class=atoi(classstr);
/*Taking input from the user */
for(int i=0;i<maxstud;i++)
{
printf("\n\n");
printf("-----STUDENT NO:%d-----\n",i+1);
printf("Student Name:");
scanf("%s",stud[i].name);
stud[i].class=class;
printf("Enter the Marks\n");
printf("Science:");
stud[i].science=legitMarkChecker();
printf("Maths:");
stud[i].maths=legitMarkChecker();
printf("Computer:");
stud[i].computer=legitMarkChecker();
fflush(NULL);
avgmark=((float)(stud[i].computer+stud[i].maths+stud[i].science)/3);
stud[i].average=avgmark;
stud[i].grade=grading(avgmark);
}
/*Printing the details of the students*/
printf("\n\n---------STUDENT DETAILS---------\n\n");
for(int i=0;i<maxstud;i++)
{
printf("NAME:%s\n",stud[i].name);
printf("CLASS:%d\n",stud[i].class);
printf("MARKS:::Science:%d\tMaths:%d\tComputer:%d",stud[i].science,stud[i].maths,stud[i].computer);
printf("\nYour Average:%0.2f",stud[i].average);
printf("\nYour Grade:%c",stud[i].grade);
printf("\n\n\n");
}
}
/*
----------STUDENT RESULT VIEWER----------
This program takes input of a student and prints their details using structure in c
->Features to add
1.Auto grading
2.Input testing
3.More(not decided yet)
->ADDITIONS
1.A legit mark fuction is added to check if the input is a mark in the limits of 0 and 100
->ISSUES
1.legitMarkChecker() runs to an infinite loop when input other than a number is entered
*/