I'm writing this grading program that calculates and displays a students grades and after all the students have been entered, it displays(or at least it should) display the group totals. The problem is, everytime i run the program, the program crashes. I can't seem to figure out why it does that. I'd really appreciate it if someone could help me out a bit. Any advice would be really helpful. Thanks!
ps. i wasn't able to calculate the
classes average grade yet.
Code:#include <cstdlib> #include <iostream> using namespace std; struct studentRecord //structure definition { int studentID; char first_name[21]; char last_name[11]; int quiz_1; int quiz_2; int midterm_score; int final_score; int totalpts; double percent; char grade; }; studentRecord student; //structure variable student //declaring constants const int maxpts = 200; //declare function prototypes bool moreStudents(); void getInput(studentRecord &myStudent); double computePercent(int totalpts, int); int computePointsEarned(int quiz_1, int quiz_2, int midterm_score, int final_score); void displayRecord(studentRecord); void displayTotals(int totalStudents, double highest, double lowest, double avgPoints); int computeHighestPoints(int numbers1, int numbers2); int computeLowestPoints(int numbers1, int numbers2); int computeClassPoints (int numbers1, int numbers2); double computeAveragePoints(int allPoints, int totalStudents); char computeGrade(double input); int main() { //declare variables int totalStudents = 0; int highest = 0; int lowest = 0; int allPoints; double avgPoints; //adjusts number output cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(1); do { getInput(student); displayRecord(student); student.percent = computePercent(student.totalpts, maxpts); student.totalpts = computePointsEarned(student.quiz_1, student.quiz_2, student.midterm_score, student.final_score); student.grade = computeGrade(student.percent); highest = computeHighestPoints(highest, student.totalpts); lowest = computeLowestPoints(lowest, student.totalpts); allPoints = computeClassPoints(allPoints, student.totalpts); avgPoints = computeAveragePoints(allPoints, totalStudents); totalStudents++; //add 1 to student counter }while(moreStudents()); //calls the moreStudents() function displayTotals(totalStudents, highest, lowest, avgPoints); system("PAUSE"); return 0; } //end main() //functions bool moreStudents() { bool more = false; char anotherStudent = 'n'; cout << "\n\nWould You like to enter another student? enter 'y' or 'Y' and press ENTER; \n"; cout << "if not, enter any other character and press ENTER "; if(anotherStudent == 'y' || anotherStudent == 'Y') more = true; else more = false; return more; } //end anotherStudent void getInput (studentRecord &myStudent) { int ID; string message = "\n\nEnter Student ID: "; do { cout << message; cin >> ID; message = "\n\nError! Please Re-Enter Student ID (1-99999): "; } while (ID < 1 || ID > 99999); myStudent.studentID = ID; //asks user to input first and last name cout << "Enter First Name: "; cin >> myStudent.first_name; cout << "Enter Last Name: "; cin >> myStudent.last_name; //determines quiz #1 score int Quiz1; string message1 = "Please enter Quiz #1 score: "; do { cout << message1; cin >> Quiz1; message1 = "\n\nError! Please Re-Enter Quiz #1 score: "; } while (Quiz1 < 0 || Quiz1 > 25); myStudent.quiz_1 = Quiz1; //determines quiz #2 score int Quiz2; string message2 = "Please enter Quiz #2 score: "; do { cout << message2; cin >> Quiz2; message = "\n\nError! Please Re-Enter Quiz #2 2core: "; } while (Quiz2 < 0 || Quiz2 > 25); myStudent.quiz_2 = Quiz2; //determines midterm score int Midterm; string message3 = "Please enter Midterm score: "; do { cout << message3; cin >> Midterm; message = "\n\nError! Please Re-Enter Midterm 2core: "; } while (Midterm < 0 || Midterm > 50); myStudent.midterm_score = Midterm; //determines final score int Final; string message4 = "Please enter Final score: "; do { cout << message4; cin >> Final; message = "\n\nError! Please Re-Enter Final score: "; } while (Final < 0 || Final > 100); myStudent.final_score = Final; } //end getInput() int computeHighestPoints(int numbers1, int numbers2) { if (numbers1 >= numbers2) return numbers1; else return numbers2; }//end computeHighestPoints int computeLowestPoints(int numbers1, int numbers2) { if (numbers1 <=numbers2) return numbers1; else return numbers2; }//end computeLowestPoints int computeClassPoints(int numbers1, int numbers2) { return (numbers1 + numbers2); }//end computeAllPoints double computeAveragePoints(int allPoints, int totalStudents) { return (allPoints/totalStudents); }//end computeAveragePoints double computePercent(int total, int max) { //calculates percentage int output; output = (maxpts)/total*100; return output; } //end computePercent int computePointsEarned(int quiz_1, int quiz_2, int midterm_score, int final_score) { //calculates total points earned int output; output = quiz_1 + quiz_2 + midterm_score + final_score; return output; } //end computePointsEarned char computeGrade(double input) { if (input >= 90) return 'A'; else if (input >= 80) return 'B'; else if (input >= 70) return 'C'; else if (input >= 60) return 'D'; else return 'F'; }//end computeGrade void displayRecord(studentRecord staff) { //display input data cout << "\n\nStudent ID: " << staff.studentID; cout << "\nFirst Name: " << staff.first_name; cout << "\nLast Name: " << staff.last_name; cout << "\nQuiz #1 Score: " << staff.quiz_1; cout << "\nQuiz#2 Score: " << staff.quiz_2; cout << "\nMidterm Score: " << staff.midterm_score; cout << "\nFinal Score: " << staff.final_score; cout << "\nTotal Points Earned: " << staff.totalpts; cout << "\nOverall Percentage: " << staff.percent; cout << "\nLetter Grade: " << staff.grade; } //end of displayRecord void displayTotals(int totalStudents, double highest, double lowest, double avgPoints) { cout << "\n--------------------------------------------\n\n"; cout << "Total Students = " << totalStudents; cout << "\nHighest Total Points Earned = " << highest; cout << "\nLowest Total Points Earned = " << lowest; cout << "\nAverage Total Points Earned = " << avgPoints; cout << "\nAverage Letter Grade Earned = ???"; }//end displayTotals



LinkBack URL
About LinkBacks



Want to add some
I used to be an adventurer like you... then I took an arrow to the knee.