Grade program, pass/fail

This is a discussion on Grade program, pass/fail within the C++ Programming forums, part of the General Programming Boards category; I'm actually just playing around with this program. It asks how many students are in the class, it asks for ...

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    13

    Grade program, pass/fail

    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();
    
    }

  2. #2
    Registered User
    Join Date
    Sep 2006
    Location
    tx
    Posts
    8
    steps

    1. get input the from user to send scores to some variables (or initialize some variables to a certain score)
    2. do calculations on those variables to get the overall grade
    3. send the overall grade variable to a switch statement or use multiple if-else (like the letter_grade function in your post) that outputs if student pass/fails

    I'm just going to write out a very simple way to do it. This is just the main function.

    Code:
    int main(){
    int score1, score2, score3, total;  // could use arrays but this is just for simplicity
    
    cout<<"enter 3 scores";
    cin>>score1>>score2>>score3;
    total = score1+score2+score3; // this is just adding. rewrite to perform your own calculations.
    
    switch(total)
    {
    
    case 150: cout<<"bad for 3 tests.";
    break;
    
    case 300: cout<<"you're a genius. perfect scores!";
    break;
    
    default: cout<<"sorry. can't analyze the total";
    }//end of switch statement
    
    return 0;
    }//end of main function
    Last edited by Salem; 12-02-2007 at 05:12 AM. Reason: Added code tags, learn to use them.

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,031
    This is C, not C++. Also get rid of that global variable and make main return int.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program Loops Forver! HELP!
    By glossopjames in forum C Programming
    Replies: 6
    Last Post: 12-16-2004, 08:23 AM
  2. insufficient memory for tsr
    By manmohan in forum C Programming
    Replies: 8
    Last Post: 01-02-2004, 09:48 AM
  3. Date program starts DOS's date
    By jrahhali in forum C++ Programming
    Replies: 1
    Last Post: 11-24-2003, 05:23 PM
  4. Grade distribution program
    By MyTeachersANazi in forum C++ Programming
    Replies: 4
    Last Post: 03-26-2003, 09:54 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 11:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21