| | |
Temporary values not adding up?
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2009
Posts: 12
Reputation:
Solved Threads: 0
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.
Thanks in advance,
24 man hours to one simple program can take its toll on a person.
C++ Syntax (Toggle Plain Text)
//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; }
•
•
Join Date: Sep 2009
Posts: 283
Reputation:
Solved Threads: 31
1
#3 Oct 20th, 2009
you are assigning your temps TO the record.totalpoints when the temps haven't been assigned any value.
also, your temp1,temp2,temp3 are not in scope with the class_avg function. pass them in as arguments. you should only need one while loop, if there is just a set number of records, use a for loop.
it's easy to get overwhelmed, but just take a step back and sketch it out on a piece of paper
also, your temp1,temp2,temp3 are not in scope with the class_avg function. pass them in as arguments. you should only need one while loop, if there is just a set number of records, use a for loop.
it's easy to get overwhelmed, but just take a step back and sketch it out on a piece of paper
1
#4 Oct 20th, 2009
i just had a glance at your code
you declared
and used
mismatch in variable names
you must be getting compilation errors.
correct the names first, and you are not updating the global variables how will the changes be effected
.
you declared
C++ Syntax (Toggle Plain Text)
int temp_1, temp_2, temp_3;
and used
C++ Syntax (Toggle Plain Text)
record.total_points = temp1; record.total_points = temp2; record.total_points = temp3;
mismatch in variable names
you must be getting compilation errors.
correct the names first, and you are not updating the global variables how will the changes be effected
.
Minds are like parachutes - they only work when they are open
Gaiety
Gaiety
•
•
Join Date: Oct 2009
Posts: 12
Reputation:
Solved Threads: 0
0
#5 Oct 20th, 2009
OK so i added temp1, temp2, temp 3 as arguments to the class_avg() function but it is still not working.
I think its because im still not assigning values to temp_1 temp_2 and temp_3.
Any ideas?
Thanks again
I think its because im still not assigning values to temp_1 temp_2 and temp_3.
Any ideas?
Thanks again
C++ Syntax (Toggle Plain Text)
//Marc Capul //10/14/09 //10/14/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); double class_avg(int temp1, int temp2, int temp3); int main() { char ans; student record, record1, record2, record3; { n++; get_data(record1); record.total_points = temp_1; calc_grade(record1); show_results(record1); cout << temp_1; 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); record.total_points = temp_2; calc_grade(record2); 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); record.total_points = temp_3; calc_grade(record3); 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(temp_1, temp_2, temp_3); 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; } double class_avg(int temp1, int temp2, int temp3) { double avg_points, avg_percent; char letter_grade; cout << endl; cout << "Number of students processed:" << n << endl; cout << temp1 << endl << temp2 << temp3 << endl; total_points = temp1 + temp2 + temp3; cout << total_points << endl; 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; }
•
•
Join Date: Nov 2008
Posts: 392
Reputation:
Solved Threads: 72
1
#6 Oct 20th, 2009
First things first: Dont use system("Pause") it has been discussed to death here and everywhere on the web.
Second: The next problem is that you are using temp1 without initializing it. i.e every time you run the program it could start with a different value and you don't know what it is.
Third: you use a struct student, BUT by not having a constructor in this object all the variables DO NOT GET INITIALIZED. Therefore your have another problem.
Four: You really really need an array of students. it would make the code MUCH shorter.
Five : Semi colon after the
Six: the reason that your class_ave does not work is that your pass three uninitialized variables. Then you have the logic wrong. Ok. Consider that you wish to pass up to three students, then temp_1 etc
should be the three values the students get.
You might chose to do that like this
Note, the thing that is getting you mixed up is that the values or VARIABLES that you use to call the function are not the same names as are in the declaration of the function, you can equally call the function like this
[icode]class_ave(40,45,34);[icode]
Note that you have then made another error. Your values in are int. This is not correct, since you are taking an average percentage on four tests and that can be 45.5 or a non-iteger number
Finally you are then forgetting what happens to the average when you enter only one student, you must NOT use the second and third values because they are meaningless.
Sorry that was a bit long, but your HAVE to go through this on paper.
It will really really help to write out a piece of paper with all the variable names and their values. If you don't give it one to start assume something very big or very negative and see what you get.
As you get better, you can then do that with the debugger, and finally, you will be able to read the code. Interestingly once you get to that stage, it seems that you can easily do that for almost any other language that you learn, I don't know why or how..
Best of luck..
Second: The next problem is that you are using temp1 without initializing it. i.e every time you run the program it could start with a different value and you don't know what it is.
Third: you use a struct student, BUT by not having a constructor in this object all the variables DO NOT GET INITIALIZED. Therefore your have another problem.
Four: You really really need an array of students. it would make the code MUCH shorter.
Five : Semi colon after the
while (ans=='y' || ans=='Y') ; is wrong. because then the while does nothing, or loopes indefinately Six: the reason that your class_ave does not work is that your pass three uninitialized variables. Then you have the logic wrong. Ok. Consider that you wish to pass up to three students, then temp_1 etc
should be the three values the students get.
You might chose to do that like this
c++ Syntax (Toggle Plain Text)
// THIS IS IN YOUR MAIN: class_ave(record1.total,record2.total,record2.total);
Note, the thing that is getting you mixed up is that the values or VARIABLES that you use to call the function are not the same names as are in the declaration of the function, you can equally call the function like this
[icode]class_ave(40,45,34);[icode]
Note that you have then made another error. Your values in are int. This is not correct, since you are taking an average percentage on four tests and that can be 45.5 or a non-iteger number
Finally you are then forgetting what happens to the average when you enter only one student, you must NOT use the second and third values because they are meaningless.
Sorry that was a bit long, but your HAVE to go through this on paper.
It will really really help to write out a piece of paper with all the variable names and their values. If you don't give it one to start assume something very big or very negative and see what you get.
As you get better, you can then do that with the debugger, and finally, you will be able to read the code. Interestingly once you get to that stage, it seems that you can easily do that for almost any other language that you learn, I don't know why or how..
Best of luck..
experience is the most expensive way to learn anything
•
•
Join Date: Oct 2009
Posts: 12
Reputation:
Solved Threads: 0
0
#7 Oct 20th, 2009
ok i tried to fix going by what you said and still nothing. also we cant use arrays because we haven't learned about them yet.
C++ Syntax (Toggle Plain Text)
//Marc Capul //10/14/09 //10/14/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(student& record, record1, record2, record3); int main() { char ans; student record, record1, record2, record3; { n++; get_data(record1); record.total_points = record1.total_points; calc_grade(record1); show_results(record1); cout << temp_1; 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); record.total_points = record2.total_points; calc_grade(record2); 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); record.total_points = record3.total_points; calc_grade(record3); 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(record, record1.total_points, record2.total_points, record3.total_points); 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(student& record, record1, record2, record3) { double avg_points, avg_percent; char letter_grade; cout << endl; cout << "Number of students processed:" << n << endl; cout << temp1 << endl << temp2 << temp3 << endl; total_points = temp1 + temp2 + temp3; cout << total_points << endl; avg_points = total_points/n; cout << "Average total points:" << avg_points; avg_percent = avg_points/200; 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; }
•
•
Join Date: Oct 2009
Posts: 12
Reputation:
Solved Threads: 0
0
#9 Oct 20th, 2009
scratch that last post. ok i changed it a little but this time it is giving me weird numbers for low score and average total points. ive also made it display the total_points for each student but still they give the wrong values except for student 2.
C++ Syntax (Toggle Plain Text)
//Marc Capul //10/14/09 //10/14/09 //CISC 192 C/C++ Programming //Prof. Johnson //Assignment 3 // WEEK 9 #include <iostream> using namespace std; int n=0; int temp_1, temp_2, temp_3, avg; struct student { string name_first, name_last; char letter_grade; double student_num, quiz_1, quiz_2, mid_exam, final_exam; int total_points,; double percent_total, class_total, class_avg; }; void get_data(student&); void calc_grade(student& record); void show_results(student& record); void class_avg(int i, int temp1, int temp2, int temp3); int main() { char ans; student record, record1, record2, record3; { n++; get_data(record1); temp_1 = record1.total_points; calc_grade(record1); show_results(record1); 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); temp_2 = record2.total_points; calc_grade(record2); 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); temp_3 = record3.total_points; calc_grade(record3); 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(n, temp_1, temp_2, temp_3); 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(int i, int temp1, int temp2, int temp3) { char avg_grade; double avg_percent; int highest; int lowest; int avg_score; avg_score = (temp1 + temp2 + temp3)/3; avg_percent = ((temp1 + temp2 + temp3)/6); cout << "Number of students processed: " << i << "\n"; if (temp1 > temp2 && temp1 > temp3) { highest = temp1; cout << "Highest total points achieved: " << highest << "\n"; } else if (temp2 > temp1 && temp2 > temp3) { highest = temp2; cout << "Highest total points achieved: " << highest << "\n"; } else if (temp3 > temp1 && temp3 > temp2) { highest = temp3; cout << "Highest total points achieved: " << highest << "\n"; } if (avg_percent >=90) { avg_grade = 'A'; } else if (avg_percent >= 80 && avg_percent < 90) { avg_grade = 'B'; } else if (avg_percent >= 70 && avg_percent < 80) { avg_grade = 'C'; } else if (avg_percent >= 60 && avg_percent < 70) { avg_grade = 'D'; } else avg_grade = 'F'; if (temp1 < temp2 && temp1 < temp3) { lowest = temp1; cout << "Lowest total points achieved: " << lowest << "\n"; } else if (temp2 < temp1 && temp2 < temp3) { lowest = temp2; cout << "Lowest total points achieved: " << lowest << "\n"; } else if (temp3 < temp1 && temp3 < temp2) { lowest = temp3; cout << "Lowest total points achieved: " << lowest << "\n"; } cout << "Average total points achieved: " << avg_score << "\n"; cout << "Average letter grade achieved: " << avg_grade << "\n"; cout << temp1 << endl << temp2 << endl << temp3; }
Last edited by mcap61; Oct 20th, 2009 at 7:40 pm.
•
•
Join Date: Oct 2009
Posts: 12
Reputation:
Solved Threads: 0
0
#10 Oct 20th, 2009
OK I almost got it!
The only problem is that my student total score 3 shows up as zero.
The only problem is that my student total score 3 shows up as zero.
C++ Syntax (Toggle Plain Text)
//Marc Capul //10/14/09 //10/14/09 //CISC 192 C/C++ Programming //Prof. Johnson //Assignment 3 // WEEK 9 #include <iostream> using namespace std; int n=0; double temp_1, temp_2, temp_3, avg; struct student { string name_first, name_last; char letter_grade; double student_num, quiz_1, quiz_2, mid_exam, final_exam; double total_points; double percent_total, class_total, class_avg; }; void get_data(student&); void calc_grade(student& record); void show_results(student& record); void class_avg(int i, double temp1, double temp2, double temp3); int main() { char ans; student record1, record2, record3; { n++; get_data(record1); temp_1 = record1.total_points; calc_grade(record1); show_results(record1); 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); temp_2 = record2.total_points; calc_grade(record2); 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); temp_3 = record3.total_points; calc_grade(record3); 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(n, temp_1, temp_2, temp_3); 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; } record.total_points = (record.quiz_1 + record.quiz_2 + record.mid_exam + 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.quiz_1 + record.quiz_2 + record.mid_exam + record.final_exam)/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(int i, double temp1, double temp2, double temp3) { char avg_grade; double avg_percent; double highest, lowest; double avg_score; avg_score = ((temp1 + temp2 + temp3)/(n)); avg_percent = ((temp1 + temp2 + temp3)/ (2*i)); cout << "Number of students processed: " << i << "\n"; if (temp1 > temp2 && temp1 > temp3) { highest = temp1; cout << "Highest total points achieved: " << highest << "\n"; } else if (temp2 > temp1 && temp2 > temp3) { highest = temp2; cout << "Highest total points achieved: " << highest << "\n"; } else if (temp3 > temp1 && temp3 > temp2) { highest = temp3; cout << "Highest total points achieved: " << highest << "\n"; } if (avg_percent >=90) { avg_grade = 'A'; } else if (avg_percent >= 80 && avg_percent < 90) { avg_grade = 'B'; } else if (avg_percent >= 70 && avg_percent < 80) { avg_grade = 'C'; } else if (avg_percent >= 60 && avg_percent < 70) { avg_grade = 'D'; } else avg_grade = 'F'; if (temp1 < temp2 && temp1 < temp3) { lowest = temp1; cout << "Lowest total points achieved: " << lowest << "\n"; } else if (temp2 < temp1 && temp2 < temp3) { lowest = temp2; cout << "Lowest total points achieved: " << lowest << "\n"; } else if (temp3 < temp1 && temp3 < temp2) { lowest = temp3; cout << "Lowest total points achieved: " << lowest << "\n"; } cout << "Average total points achieved: " << avg_score << "\n"; cout << "Average letter grade achieved: " << avg_grade << "\n"; cout << temp1 << endl << temp2 << endl << temp3; }
![]() |
Similar Threads
- getting values in jtable (Java)
- about registry key . . . (Visual Basic 4 / 5 / 6)
- Link Views are not Adding Please some one Help me. (ASP)
- what is wrong in this code (4 add and mul.)? (Graphics and Multimedia)
- C++ TMoney Class - I Can't Figure This Out. (C++)
- New in C++ Help with Arrays (C++)
- How to add a vector content in to the hashtable as a value (Java)
- Reading Controls from Panel (ASP.NET)
- I need advices for the Pseudocode (JavaScript / DHTML / AJAX)
Other Threads in the C++ Forum
- Previous Thread: what does it mean , the Q is not clear !
- Next Thread: Visual Studio C++ 2008 Mess-Up
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news node numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector visualstudio win32 windows winsock word wordfrequency wxwidgets






