I'm actually just playing around with this program. It asks how many students are in the class, it asks for the student ID, then for each student it asks for three grades. It outputs each student's three grades, average, and letter grade.
What I would like it to do is JUST tell whether the student passed or failed, OR just tell the letter grade. How would I go about doing this?
I don't need it to ask for the number of students, I just need it to work with one. Therefore it doesn't need to ask for a student ID.
I just need it simplified
Thanks.
Code:
#include <stdio.h>
#define MAXSTUDENTS 25
int totalStudents;
struct studentrec {
int q1,
q2,
q3,
id,
avg;
char grade;
} studentRecordsStructure[MAXSTUDENTS];
int checkID( int temp ) {
int myBool, y;
myBool = 1;
printf(" verifying unique ID....");
for (y = 0; y < totalStudents; y++){
if (temp == studentRecordsStructure[y].id) {
printf("\nthe ID \"%d\" is taken. try another. >", temp);
return myBool;
}
}
myBool = 0;
printf(" ID %d accepted.\n", temp);
return myBool;
}
void get_a_rec( struct studentrec *student ) {
int temp, boolean;
boolean = 1;
printf("\n please enter student ID : ");
do {
scanf ("%d", &student->id);
boolean = checkID(student->id);
} while (boolean == 1);
printf(" :: quiz 1 :: ");
scanf ("%d", &student->q1);
printf(" :: quiz 2 :: ");
scanf ("%d", &student->q2);
printf(" :: quiz 3 :: ");
scanf ("%d", &student->q3);
}
int average ( struct studentrec student ) {
int sum = 0;
sum = student.q1 + student.q2 + student.q3;
return sum / 3;
}
char letter_grade ( int score ) {
if (score >= 90) return 'A';
else if (score >= 80) return 'B';
else if (score >= 70) return 'C';
else if (score >= 60) return 'D';
else return 'F';
}
void getStudentRecords() {
int i, cont;
cont = 0;
totalStudents = 0;
do{
printf("\n\nHow many students are in your class? (MAX = 25) > ");
scanf ("%d", &totalStudents);
if ( (totalStudents <= MAXSTUDENTS) && ( totalStudents > 0 ) ) { cont = 1; }
} while (cont == 0);
for (i = 0; i < totalStudents; i++) {
struct studentrec st1;
get_a_rec ( &st1 );
st1.avg = average( st1 );
st1.grade = letter_grade ( st1.avg );
studentRecordsStructure[i]= st1;
}
}
void sortStudentRecords() {
int u, v;
struct studentrec sortTemp;
for ( u = 0; u < (totalStudents - 1); u++) {
for ( v = 0; v < (totalStudents - (u + 1)); v++) {
if ( studentRecordsStructure[v].avg < studentRecordsStructure[v+1].avg ) {
sortTemp = studentRecordsStructure[v];
studentRecordsStructure[v] = studentRecordsStructure[v+1];
studentRecordsStructure[v+1] = sortTemp;
}
}
}
}
void printStudentRecords() {
int j;
printf(" \n\n");
printf(" ID____Q1____Q2____Q3____AVG___LTR_\n");
for (j = 0; j < totalStudents; j++) {
printf(" %3d ..%3d . %3d . %3d .. %3d . %3c \n",
studentRecordsStructure[j].id,
studentRecordsStructure[j].q1,
studentRecordsStructure[j].q2,
studentRecordsStructure[j].q3,
studentRecordsStructure[j].avg,
studentRecordsStructure[j].grade);
} printf("\nciao.\n\n");
}
main() {
getStudentRecords();
sortStudentRecords();
printStudentRecords();
}