OK, so i need help adding my total_points = temp1 + temp2 + temp3, but everytime they just equal 0. This is a student grade class average program, where you enter a student's info, it gets calculated, then you add the next, after entering all studen't you have to figure out the class average which i am having a hard time doing
Thanks in advance,
24 man hours to one simple program can take its toll on a person.
//Marc Capul
//10/18/09
//10/18/09
//CISC 192 C/C++ Programming
//Prof. Johnson
//Assignment 3
// WEEK 9
#include <iostream>
using namespace std;
int n=0;
double total_points;
int temp_1, temp_2, temp_3;
struct student
{
string name_first, name_last;
char letter_grade;
double student_num, quiz_1, quiz_2, mid_exam, final_exam, total_points,;
double percent_total, class_total, class_avg;
};
void get_data(student& record);
void calc_grade(student& record);
void show_results(student& record);
void class_avg();
int main()
{
char ans;
student record, record1, record2, record3;
{
n++;
get_data(record1);
calc_grade(record1);
record.total_points = temp1;
show_results(record1);
cout << temp1;
cout << "Is there another student's scores that need to be processed?";
cout << endl;
cout << "Press 'y' or 'Y' for yes or 'n' for Class Summary.";
cin >> ans;
}
while (ans == 'y' || ans == 'Y');
{
n++;
get_data(record2);
calc_grade(record2);
record.total_points = temp2;
show_results(record2);
cout << "Is there another student's scores that need to be processed?";
cout << endl;
cout << "Press 'y' or 'Y' for yes or 'n' for Class Summary.";
cin >> ans;
}
while (ans == 'y' || ans == 'Y');
{
n++;
get_data(record3);
calc_grade(record3);
record.total_points = temp3;
show_results(record3);
cout << "Is there another student's scores that need to be processed?";
cout << endl;
cout << "Press 'y' or 'Y' for yes or 'n' for Class Summary.";
cin >> ans;
}
class_avg();
system("PAUSE");
return 0;
}
void get_data(student& record)
{
cout << "Please enter the following:\n";
cout << "Student ID number:";
cin >> record.student_num;
while (record.student_num < 1 || record.student_num > 99999)
{
cout << "Invalid Student ID number.\n";
cout << "Please enter again.\n";
cin >> record.student_num;
}
cout << "First name:";
cin >> record.name_first;
cout << "Last name:";
cin >> record.name_last;
cout << "Quiz #1 score:";
cin >> record.quiz_1;
while (record.quiz_1 < 0 || record.quiz_1 > 25)
{
cout << "Invalid quiz score.\n";
cout << "Please enter again.\n";
cin >> record.quiz_1;
}
cout << "Quiz #2 Score:";
cin >> record.quiz_2;
while (record.quiz_2 < 0 || record.quiz_2 > 25)
{
cout << "Invalid quiz score.\n";
cout << "Please enter again.\n";
cin >> record.quiz_2;
}
cout << "Midterm exam score:";
cin >> record.mid_exam;
while (record.mid_exam < 0 || record.mid_exam > 50)
{
cout << "Invalid exam score.\n";
cout << "Please enter again.\n";
cin >> record.mid_exam;
}
cout << "Final exam score:";
cin >> record.final_exam;
while (record.final_exam < 0 || record.final_exam > 100)
{
cout << "Invalid exam score.\n";
cout << "Please enter again.\n";
cin >> record.final_exam;
}
}
void calc_grade(student& record)
{
char letter_grade;
record.total_points = (record.quiz_1 + record.quiz_2 + record.mid_exam + record.final_exam);
record.percent_total = (100)*(record.total_points/200);
if (record.percent_total >= 90)
{
record.letter_grade = 'A';
}
else if (record.percent_total >= 80 && record.percent_total < 90)
{
record.letter_grade = 'B';
}
else if (record.percent_total >= 70 && record.percent_total < 80)
{
record.letter_grade = 'C';
}
else if (record.percent_total >= 60 && record.percent_total < 70)
{
record.letter_grade = 'D';
}
else
{
record.letter_grade = 'F';
}
}
void show_results(student& record)
{
cout << "Summary:" << endl;
cout << "ID number:";
cout << record.student_num << endl;
cout << "Name:";
cout << record.name_first <<" "<< record.name_last << endl;
cout << "Quiz #1 score:";
cout << record.quiz_1 << endl;
cout << "Quiz #2 score:";
cout << record.quiz_2 << endl;
cout << "Midterm exam score:";
cout << record.mid_exam << endl;
cout << "Final exam score:";
cout << record.final_exam << endl;
cout << "Total points earned:";
cout << record.total_points << endl;
cout << "Percent Total:";
cout << record.percent_total << "%" << endl;
cout << "Grade:";
cout << record.letter_grade << endl;
}
void class_avg()
{
double avg_points, avg_percent;
char letter_grade;
cout << endl;
cout << "Number of students processed:" << n << endl;
cout << temp1 << endl << temp2 << temp3 << endl;
cout << total_points << endl;
total_points = temp1 + temp2 + temp3;
avg_points = total_points/n;
if (avg_percent >= 90)
{
letter_grade = 'A';
}
else if (avg_percent >= 80 && avg_percent < 90)
{
letter_grade = 'B';
}
else if (avg_percent >= 70 && avg_percent < 80)
{
letter_grade = 'C';
}
else if (avg_percent >= 60 && avg_percent < 70)
{
letter_grade = 'D';
}
else
{
letter_grade = 'F';
}
cout << "Average total points achieved: " << avg_points << endl;
cout << "Average letter grade: " << letter_grade;
}