Temporary values not adding up?

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2009
Posts: 12
Reputation: mcap61 is an unknown quantity at this point 
Solved Threads: 0
mcap61 mcap61 is offline Offline
Newbie Poster

Temporary values not adding up?

 
0
  #1
Oct 20th, 2009
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.

  1. //Marc Capul
  2. //10/18/09
  3. //10/18/09
  4. //CISC 192 C/C++ Programming
  5. //Prof. Johnson
  6. //Assignment 3
  7. // WEEK 9
  8.  
  9. #include <iostream>
  10. using namespace std;
  11.  
  12. int n=0;
  13. double total_points;
  14. int temp_1, temp_2, temp_3;
  15. struct student
  16. {
  17. string name_first, name_last;
  18. char letter_grade;
  19. double student_num, quiz_1, quiz_2, mid_exam, final_exam, total_points,;
  20. double percent_total, class_total, class_avg;
  21. };
  22. void get_data(student& record);
  23. void calc_grade(student& record);
  24. void show_results(student& record);
  25. void class_avg();
  26.  
  27. int main()
  28. {
  29. char ans;
  30. student record, record1, record2, record3;
  31. {
  32. n++;
  33. get_data(record1);
  34. calc_grade(record1);
  35. record.total_points = temp1;
  36. show_results(record1);
  37. cout << temp1;
  38. cout << "Is there another student's scores that need to be processed?";
  39. cout << endl;
  40. cout << "Press 'y' or 'Y' for yes or 'n' for Class Summary.";
  41. cin >> ans;
  42. }
  43. while (ans == 'y' || ans == 'Y');
  44. {
  45. n++;
  46. get_data(record2);
  47. calc_grade(record2);
  48. record.total_points = temp2;
  49. show_results(record2);
  50. cout << "Is there another student's scores that need to be processed?";
  51. cout << endl;
  52. cout << "Press 'y' or 'Y' for yes or 'n' for Class Summary.";
  53. cin >> ans;
  54. }
  55. while (ans == 'y' || ans == 'Y');
  56. {
  57. n++;
  58. get_data(record3);
  59. calc_grade(record3);
  60. record.total_points = temp3;
  61. show_results(record3);
  62. cout << "Is there another student's scores that need to be processed?";
  63. cout << endl;
  64. cout << "Press 'y' or 'Y' for yes or 'n' for Class Summary.";
  65. cin >> ans;
  66. }
  67. class_avg();
  68. system("PAUSE");
  69. return 0;
  70. }
  71.  
  72. void get_data(student& record)
  73. {
  74. cout << "Please enter the following:\n";
  75. cout << "Student ID number:";
  76. cin >> record.student_num;
  77. while (record.student_num < 1 || record.student_num > 99999)
  78. {
  79. cout << "Invalid Student ID number.\n";
  80. cout << "Please enter again.\n";
  81. cin >> record.student_num;
  82. }
  83. cout << "First name:";
  84. cin >> record.name_first;
  85. cout << "Last name:";
  86. cin >> record.name_last;
  87. cout << "Quiz #1 score:";
  88. cin >> record.quiz_1;
  89. while (record.quiz_1 < 0 || record.quiz_1 > 25)
  90. {
  91. cout << "Invalid quiz score.\n";
  92. cout << "Please enter again.\n";
  93. cin >> record.quiz_1;
  94. }
  95. cout << "Quiz #2 Score:";
  96. cin >> record.quiz_2;
  97. while (record.quiz_2 < 0 || record.quiz_2 > 25)
  98. {
  99. cout << "Invalid quiz score.\n";
  100. cout << "Please enter again.\n";
  101. cin >> record.quiz_2;
  102. }
  103. cout << "Midterm exam score:";
  104. cin >> record.mid_exam;
  105. while (record.mid_exam < 0 || record.mid_exam > 50)
  106. {
  107. cout << "Invalid exam score.\n";
  108. cout << "Please enter again.\n";
  109. cin >> record.mid_exam;
  110. }
  111. cout << "Final exam score:";
  112. cin >> record.final_exam;
  113. while (record.final_exam < 0 || record.final_exam > 100)
  114. {
  115. cout << "Invalid exam score.\n";
  116. cout << "Please enter again.\n";
  117. cin >> record.final_exam;
  118. }
  119. }
  120.  
  121. void calc_grade(student& record)
  122. {
  123. char letter_grade;
  124. record.total_points = (record.quiz_1 + record.quiz_2 + record.mid_exam + record.final_exam);
  125.  
  126.  
  127. record.percent_total = (100)*(record.total_points/200);
  128.  
  129.  
  130. if (record.percent_total >= 90)
  131. {
  132. record.letter_grade = 'A';
  133. }
  134. else if (record.percent_total >= 80 && record.percent_total < 90)
  135. {
  136. record.letter_grade = 'B';
  137. }
  138. else if (record.percent_total >= 70 && record.percent_total < 80)
  139. {
  140. record.letter_grade = 'C';
  141. }
  142. else if (record.percent_total >= 60 && record.percent_total < 70)
  143. {
  144. record.letter_grade = 'D';
  145. }
  146. else
  147. {
  148. record.letter_grade = 'F';
  149. }
  150. }
  151.  
  152.  
  153.  
  154. void show_results(student& record)
  155. {
  156. cout << "Summary:" << endl;
  157. cout << "ID number:";
  158. cout << record.student_num << endl;
  159. cout << "Name:";
  160. cout << record.name_first <<" "<< record.name_last << endl;
  161. cout << "Quiz #1 score:";
  162. cout << record.quiz_1 << endl;
  163. cout << "Quiz #2 score:";
  164. cout << record.quiz_2 << endl;
  165. cout << "Midterm exam score:";
  166. cout << record.mid_exam << endl;
  167. cout << "Final exam score:";
  168. cout << record.final_exam << endl;
  169. cout << "Total points earned:";
  170. cout << record.total_points << endl;
  171. cout << "Percent Total:";
  172. cout << record.percent_total << "%" << endl;
  173. cout << "Grade:";
  174. cout << record.letter_grade << endl;
  175. }
  176.  
  177. void class_avg()
  178. {
  179. double avg_points, avg_percent;
  180. char letter_grade;
  181. cout << endl;
  182. cout << "Number of students processed:" << n << endl;
  183. cout << temp1 << endl << temp2 << temp3 << endl;
  184. cout << total_points << endl;
  185. total_points = temp1 + temp2 + temp3;
  186. avg_points = total_points/n;
  187.  
  188. if (avg_percent >= 90)
  189. {
  190. letter_grade = 'A';
  191.  
  192. }
  193. else if (avg_percent >= 80 && avg_percent < 90)
  194. {
  195. letter_grade = 'B';
  196. }
  197. else if (avg_percent >= 70 && avg_percent < 80)
  198. {
  199. letter_grade = 'C';
  200. }
  201. else if (avg_percent >= 60 && avg_percent < 70)
  202. {
  203. letter_grade = 'D';
  204. }
  205. else
  206. {
  207. letter_grade = 'F';
  208. }
  209.  
  210. cout << "Average total points achieved: " << avg_points << endl;
  211. cout << "Average letter grade: " << letter_grade;
  212. }
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei
 
0
  #2
Oct 20th, 2009
Wouldn't it be helpful to us that aren't psychic to actually explain the problem? I assume you are having trouble compiling.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 283
Reputation: jonsca is an unknown quantity at this point 
Solved Threads: 31
jonsca jonsca is online now Online
Posting Whiz in Training
 
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
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 76
Reputation: Gaiety is an unknown quantity at this point 
Solved Threads: 2
Gaiety's Avatar
Gaiety Gaiety is offline Offline
Junior Poster in Training
 
1
  #4
Oct 20th, 2009
i just had a glance at your code
you declared

  1. int temp_1, temp_2, temp_3;

and used
  1. record.total_points = temp1;
  2. record.total_points = temp2;
  3. 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
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 12
Reputation: mcap61 is an unknown quantity at this point 
Solved Threads: 0
mcap61 mcap61 is offline Offline
Newbie Poster
 
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



  1. //Marc Capul
  2. //10/14/09
  3. //10/14/09
  4. //CISC 192 C/C++ Programming
  5. //Prof. Johnson
  6. //Assignment 3
  7. // WEEK 9
  8.  
  9. #include <iostream>
  10. using namespace std;
  11.  
  12. int n=0;
  13. double total_points;
  14. int temp_1, temp_2, temp_3;
  15. struct student
  16. {
  17. string name_first, name_last;
  18. char letter_grade;
  19. double student_num, quiz_1, quiz_2, mid_exam, final_exam, total_points,;
  20. double percent_total, class_total, class_avg;
  21. };
  22. void get_data(student& record);
  23. void calc_grade(student& record);
  24. void show_results(student& record);
  25. double class_avg(int temp1, int temp2, int temp3);
  26.  
  27. int main()
  28. {
  29. char ans;
  30. student record, record1, record2, record3;
  31. {
  32. n++;
  33. get_data(record1);
  34. record.total_points = temp_1;
  35. calc_grade(record1);
  36. show_results(record1);
  37. cout << temp_1;
  38. cout << "Is there another student's scores that need to be processed?";
  39. cout << endl;
  40. cout << "Press 'y' or 'Y' for yes or 'n' for Class Summary.";
  41. cin >> ans;
  42. }
  43. while (ans == 'y' || ans == 'Y');
  44. {
  45. n++;
  46. get_data(record2);
  47. record.total_points = temp_2;
  48. calc_grade(record2);
  49. show_results(record2);
  50. cout << "Is there another student's scores that need to be processed?";
  51. cout << endl;
  52. cout << "Press 'y' or 'Y' for yes or 'n' for Class Summary.";
  53. cin >> ans;
  54. }
  55. while (ans == 'y' || ans == 'Y');
  56. {
  57. n++;
  58. get_data(record3);
  59. record.total_points = temp_3;
  60. calc_grade(record3);
  61. show_results(record3);
  62. cout << "Is there another student's scores that need to be processed?";
  63. cout << endl;
  64. cout << "Press 'y' or 'Y' for yes or 'n' for Class Summary.";
  65. cin >> ans;
  66. }
  67. class_avg(temp_1, temp_2, temp_3);
  68. system("PAUSE");
  69. return 0;
  70. }
  71.  
  72. void get_data(student& record)
  73. {
  74. cout << "Please enter the following:\n";
  75. cout << "Student ID number:";
  76. cin >> record.student_num;
  77. while (record.student_num < 1 || record.student_num > 99999)
  78. {
  79. cout << "Invalid Student ID number.\n";
  80. cout << "Please enter again.\n";
  81. cin >> record.student_num;
  82. }
  83. cout << "First name:";
  84. cin >> record.name_first;
  85. cout << "Last name:";
  86. cin >> record.name_last;
  87. cout << "Quiz #1 score:";
  88. cin >> record.quiz_1;
  89. while (record.quiz_1 < 0 || record.quiz_1 > 25)
  90. {
  91. cout << "Invalid quiz score.\n";
  92. cout << "Please enter again.\n";
  93. cin >> record.quiz_1;
  94. }
  95. cout << "Quiz #2 Score:";
  96. cin >> record.quiz_2;
  97. while (record.quiz_2 < 0 || record.quiz_2 > 25)
  98. {
  99. cout << "Invalid quiz score.\n";
  100. cout << "Please enter again.\n";
  101. cin >> record.quiz_2;
  102. }
  103. cout << "Midterm exam score:";
  104. cin >> record.mid_exam;
  105. while (record.mid_exam < 0 || record.mid_exam > 50)
  106. {
  107. cout << "Invalid exam score.\n";
  108. cout << "Please enter again.\n";
  109. cin >> record.mid_exam;
  110. }
  111. cout << "Final exam score:";
  112. cin >> record.final_exam;
  113. while (record.final_exam < 0 || record.final_exam > 100)
  114. {
  115. cout << "Invalid exam score.\n";
  116. cout << "Please enter again.\n";
  117. cin >> record.final_exam;
  118. }
  119. }
  120.  
  121. void calc_grade(student& record)
  122. {
  123. char letter_grade;
  124. record.total_points = (record.quiz_1 + record.quiz_2 + record.mid_exam + record.final_exam);
  125.  
  126.  
  127. record.percent_total = (100)*(record.total_points/200);
  128.  
  129.  
  130. if (record.percent_total >= 90)
  131. {
  132. record.letter_grade = 'A';
  133. }
  134. else if (record.percent_total >= 80 && record.percent_total < 90)
  135. {
  136. record.letter_grade = 'B';
  137. }
  138. else if (record.percent_total >= 70 && record.percent_total < 80)
  139. {
  140. record.letter_grade = 'C';
  141. }
  142. else if (record.percent_total >= 60 && record.percent_total < 70)
  143. {
  144. record.letter_grade = 'D';
  145. }
  146. else
  147. {
  148. record.letter_grade = 'F';
  149. }
  150. }
  151.  
  152.  
  153.  
  154. void show_results(student& record)
  155. {
  156. cout << "Summary:" << endl;
  157. cout << "ID number:";
  158. cout << record.student_num << endl;
  159. cout << "Name:";
  160. cout << record.name_first <<" "<< record.name_last << endl;
  161. cout << "Quiz #1 score:";
  162. cout << record.quiz_1 << endl;
  163. cout << "Quiz #2 score:";
  164. cout << record.quiz_2 << endl;
  165. cout << "Midterm exam score:";
  166. cout << record.mid_exam << endl;
  167. cout << "Final exam score:";
  168. cout << record.final_exam << endl;
  169. cout << "Total points earned:";
  170. cout << record.total_points << endl;
  171. cout << "Percent Total:";
  172. cout << record.percent_total << "%" << endl;
  173. cout << "Grade:";
  174. cout << record.letter_grade << endl;
  175. }
  176.  
  177. double class_avg(int temp1, int temp2, int temp3)
  178. {
  179. double avg_points, avg_percent;
  180. char letter_grade;
  181. cout << endl;
  182. cout << "Number of students processed:" << n << endl;
  183. cout << temp1 << endl << temp2 << temp3 << endl;
  184. total_points = temp1 + temp2 + temp3;
  185. cout << total_points << endl;
  186. avg_points = total_points/n;
  187.  
  188. if (avg_percent >= 90)
  189. {
  190. letter_grade = 'A';
  191.  
  192. }
  193. else if (avg_percent >= 80 && avg_percent < 90)
  194. {
  195. letter_grade = 'B';
  196. }
  197. else if (avg_percent >= 70 && avg_percent < 80)
  198. {
  199. letter_grade = 'C';
  200. }
  201. else if (avg_percent >= 60 && avg_percent < 70)
  202. {
  203. letter_grade = 'D';
  204. }
  205. else
  206. {
  207. letter_grade = 'F';
  208. }
  209.  
  210. cout << "Average total points achieved: " << avg_points << endl;
  211. cout << "Average letter grade: " << letter_grade;
  212. }
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 392
Reputation: StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light 
Solved Threads: 72
StuXYZ StuXYZ is offline Offline
Posting Whiz
 
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 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

  1. // THIS IS IN YOUR MAIN:
  2. 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
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 12
Reputation: mcap61 is an unknown quantity at this point 
Solved Threads: 0
mcap61 mcap61 is offline Offline
Newbie Poster
 
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.

  1. //Marc Capul
  2. //10/14/09
  3. //10/14/09
  4. //CISC 192 C/C++ Programming
  5. //Prof. Johnson
  6. //Assignment 3
  7. // WEEK 9
  8.  
  9. #include <iostream>
  10. using namespace std;
  11.  
  12. int n=0;
  13. double total_points;
  14. int temp_1, temp_2, temp_3;
  15. struct student
  16. {
  17. string name_first, name_last;
  18. char letter_grade;
  19. double student_num, quiz_1, quiz_2, mid_exam, final_exam, total_points,;
  20. double percent_total, class_total, class_avg;
  21. };
  22. void get_data(student& record);
  23. void calc_grade(student& record);
  24. void show_results(student& record);
  25. void class_avg(student& record, record1, record2, record3);
  26.  
  27. int main()
  28. {
  29. char ans;
  30. student record, record1, record2, record3;
  31. {
  32. n++;
  33. get_data(record1);
  34. record.total_points = record1.total_points;
  35. calc_grade(record1);
  36. show_results(record1);
  37. cout << temp_1;
  38. cout << "Is there another student's scores that need to be processed?";
  39. cout << endl;
  40. cout << "Press 'y' or 'Y' for yes or 'n' for Class Summary.";
  41. cin >> ans;
  42. }
  43. while (ans == 'y' || ans == 'Y')
  44. {
  45. n++;
  46. get_data(record2);
  47. record.total_points = record2.total_points;
  48. calc_grade(record2);
  49. show_results(record2);
  50. cout << "Is there another student's scores that need to be processed?";
  51. cout << endl;
  52. cout << "Press 'y' or 'Y' for yes or 'n' for Class Summary.";
  53. cin >> ans;
  54. }
  55. while (ans == 'y' || ans == 'Y')
  56. {
  57. n++;
  58. get_data(record3);
  59. record.total_points = record3.total_points;
  60. calc_grade(record3);
  61. show_results(record3);
  62. cout << "Is there another student's scores that need to be processed?";
  63. cout << endl;
  64. cout << "Press 'y' or 'Y' for yes or 'n' for Class Summary.";
  65. cin >> ans;
  66. }
  67. class_avg(record, record1.total_points, record2.total_points, record3.total_points);
  68. system("PAUSE");
  69. return 0;
  70. }
  71.  
  72. void get_data(student& record)
  73. {
  74. cout << "Please enter the following:\n";
  75. cout << "Student ID number:";
  76. cin >> record.student_num;
  77. while (record.student_num < 1 || record.student_num > 99999)
  78. {
  79. cout << "Invalid Student ID number.\n";
  80. cout << "Please enter again.\n";
  81. cin >> record.student_num;
  82. }
  83. cout << "First name:";
  84. cin >> record.name_first;
  85. cout << "Last name:";
  86. cin >> record.name_last;
  87. cout << "Quiz #1 score:";
  88. cin >> record.quiz_1;
  89. while (record.quiz_1 < 0 || record.quiz_1 > 25)
  90. {
  91. cout << "Invalid quiz score.\n";
  92. cout << "Please enter again.\n";
  93. cin >> record.quiz_1;
  94. }
  95. cout << "Quiz #2 Score:";
  96. cin >> record.quiz_2;
  97. while (record.quiz_2 < 0 || record.quiz_2 > 25)
  98. {
  99. cout << "Invalid quiz score.\n";
  100. cout << "Please enter again.\n";
  101. cin >> record.quiz_2;
  102. }
  103. cout << "Midterm exam score:";
  104. cin >> record.mid_exam;
  105. while (record.mid_exam < 0 || record.mid_exam > 50)
  106. {
  107. cout << "Invalid exam score.\n";
  108. cout << "Please enter again.\n";
  109. cin >> record.mid_exam;
  110. }
  111. cout << "Final exam score:";
  112. cin >> record.final_exam;
  113. while (record.final_exam < 0 || record.final_exam > 100)
  114. {
  115. cout << "Invalid exam score.\n";
  116. cout << "Please enter again.\n";
  117. cin >> record.final_exam;
  118. }
  119. }
  120.  
  121. void calc_grade(student& record)
  122. {
  123. char letter_grade;
  124. record.total_points = (record.quiz_1 + record.quiz_2 + record.mid_exam + record.final_exam);
  125.  
  126.  
  127. record.percent_total = (100)*(record.total_points/200);
  128.  
  129.  
  130. if (record.percent_total >= 90)
  131. {
  132. record.letter_grade = 'A';
  133. }
  134. else if (record.percent_total >= 80 && record.percent_total < 90)
  135. {
  136. record.letter_grade = 'B';
  137. }
  138. else if (record.percent_total >= 70 && record.percent_total < 80)
  139. {
  140. record.letter_grade = 'C';
  141. }
  142. else if (record.percent_total >= 60 && record.percent_total < 70)
  143. {
  144. record.letter_grade = 'D';
  145. }
  146. else
  147. {
  148. record.letter_grade = 'F';
  149. }
  150. }
  151.  
  152.  
  153.  
  154. void show_results(student& record)
  155. {
  156. cout << "Summary:" << endl;
  157. cout << "ID number:";
  158. cout << record.student_num << endl;
  159. cout << "Name:";
  160. cout << record.name_first <<" "<< record.name_last << endl;
  161. cout << "Quiz #1 score:";
  162. cout << record.quiz_1 << endl;
  163. cout << "Quiz #2 score:";
  164. cout << record.quiz_2 << endl;
  165. cout << "Midterm exam score:";
  166. cout << record.mid_exam << endl;
  167. cout << "Final exam score:";
  168. cout << record.final_exam << endl;
  169. cout << "Total points earned:";
  170. cout << record.total_points << endl;
  171. cout << "Percent Total:";
  172. cout << record.percent_total << "%" << endl;
  173. cout << "Grade:";
  174. cout << record.letter_grade << endl;
  175. }
  176.  
  177. void class_avg(student& record, record1, record2, record3)
  178. {
  179. double avg_points, avg_percent;
  180. char letter_grade;
  181. cout << endl;
  182. cout << "Number of students processed:" << n << endl;
  183. cout << temp1 << endl << temp2 << temp3 << endl;
  184. total_points = temp1 + temp2 + temp3;
  185. cout << total_points << endl;
  186. avg_points = total_points/n;
  187. cout << "Average total points:" << avg_points;
  188. avg_percent = avg_points/200;
  189.  
  190. if (avg_percent >= 90)
  191. {
  192. letter_grade = 'A';
  193.  
  194. }
  195. else if (avg_percent >= 80 && avg_percent < 90)
  196. {
  197. letter_grade = 'B';
  198. }
  199. else if (avg_percent >= 70 && avg_percent < 80)
  200. {
  201. letter_grade = 'C';
  202. }
  203. else if (avg_percent >= 60 && avg_percent < 70)
  204. {
  205. letter_grade = 'D';
  206. }
  207. else
  208. {
  209. letter_grade = 'F';
  210. }
  211.  
  212. cout << "Average total points achieved: " << avg_points << endl;
  213. cout << "Average letter grade: " << letter_grade;
  214. }
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 12
Reputation: mcap61 is an unknown quantity at this point 
Solved Threads: 0
mcap61 mcap61 is offline Offline
Newbie Poster
 
0
  #8
Oct 20th, 2009
edit delete
Last edited by mcap61; Oct 20th, 2009 at 6:42 pm.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 12
Reputation: mcap61 is an unknown quantity at this point 
Solved Threads: 0
mcap61 mcap61 is offline Offline
Newbie Poster
 
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.

  1. //Marc Capul
  2. //10/14/09
  3. //10/14/09
  4. //CISC 192 C/C++ Programming
  5. //Prof. Johnson
  6. //Assignment 3
  7. // WEEK 9
  8.  
  9. #include <iostream>
  10. using namespace std;
  11.  
  12. int n=0;
  13. int temp_1, temp_2, temp_3, avg;
  14. struct student
  15. {
  16. string name_first, name_last;
  17. char letter_grade;
  18. double student_num, quiz_1, quiz_2, mid_exam, final_exam;
  19. int total_points,;
  20. double percent_total, class_total, class_avg;
  21. };
  22.  
  23. void get_data(student&);
  24. void calc_grade(student& record);
  25. void show_results(student& record);
  26. void class_avg(int i, int temp1, int temp2, int temp3);
  27.  
  28.  
  29. int main()
  30. {
  31. char ans;
  32. student record, record1, record2, record3;
  33. {
  34. n++;
  35. get_data(record1);
  36. temp_1 = record1.total_points;
  37. calc_grade(record1);
  38. show_results(record1);
  39. cout << "Is there another student's scores that need to be processed?";
  40. cout << endl;
  41. cout << "Press 'y' or 'Y' for yes or 'n' for Class Summary.";
  42. cin >> ans;
  43. }
  44. while (ans == 'y' || ans == 'Y')
  45. {
  46. n++;
  47. get_data(record2);
  48. temp_2 = record2.total_points;
  49. calc_grade(record2);
  50. show_results(record2);
  51. cout << "Is there another student's scores that need to be processed?";
  52. cout << endl;
  53. cout << "Press 'y' or 'Y' for yes or 'n' for Class Summary.";
  54. cin >> ans;
  55. }
  56. while (ans == 'y' || ans == 'Y')
  57. {
  58. n++;
  59. get_data(record3);
  60. temp_3 = record3.total_points;
  61. calc_grade(record3);
  62. show_results(record3);
  63. cout << "Is there another student's scores that need to be processed?";
  64. cout << endl;
  65. cout << "Press 'y' or 'Y' for yes or 'n' for Class Summary.";
  66. cin >> ans;
  67. }
  68. class_avg(n, temp_1, temp_2, temp_3);
  69. system("PAUSE");
  70. return 0;
  71. }
  72.  
  73. void get_data(student& record)
  74. {
  75. cout << "Please enter the following:\n";
  76. cout << "Student ID number:";
  77. cin >> record.student_num;
  78. while (record.student_num < 1 || record.student_num > 99999)
  79. {
  80. cout << "Invalid Student ID number.\n";
  81. cout << "Please enter again.\n";
  82. cin >> record.student_num;
  83. }
  84. cout << "First name:";
  85. cin >> record.name_first;
  86. cout << "Last name:";
  87. cin >> record.name_last;
  88. cout << "Quiz #1 score:";
  89. cin >> record.quiz_1;
  90. while (record.quiz_1 < 0 || record.quiz_1 > 25)
  91. {
  92. cout << "Invalid quiz score.\n";
  93. cout << "Please enter again.\n";
  94. cin >> record.quiz_1;
  95. }
  96. cout << "Quiz #2 Score:";
  97. cin >> record.quiz_2;
  98. while (record.quiz_2 < 0 || record.quiz_2 > 25)
  99. {
  100. cout << "Invalid quiz score.\n";
  101. cout << "Please enter again.\n";
  102. cin >> record.quiz_2;
  103. }
  104. cout << "Midterm exam score:";
  105. cin >> record.mid_exam;
  106. while (record.mid_exam < 0 || record.mid_exam > 50)
  107. {
  108. cout << "Invalid exam score.\n";
  109. cout << "Please enter again.\n";
  110. cin >> record.mid_exam;
  111. }
  112. cout << "Final exam score:";
  113. cin >> record.final_exam;
  114. while (record.final_exam < 0 || record.final_exam > 100)
  115. {
  116. cout << "Invalid exam score.\n";
  117. cout << "Please enter again.\n";
  118. cin >> record.final_exam;
  119. }
  120. }
  121.  
  122. void calc_grade(student& record)
  123. {
  124. char letter_grade;
  125. record.total_points = (record.quiz_1 + record.quiz_2 + record.mid_exam + record.final_exam);
  126.  
  127.  
  128. record.percent_total = (100)*(record.total_points/200);
  129.  
  130.  
  131. if (record.percent_total >= 90)
  132. {
  133. record.letter_grade = 'A';
  134. }
  135. else if (record.percent_total >= 80 && record.percent_total < 90)
  136. {
  137. record.letter_grade = 'B';
  138. }
  139. else if (record.percent_total >= 70 && record.percent_total < 80)
  140. {
  141. record.letter_grade = 'C';
  142. }
  143. else if (record.percent_total >= 60 && record.percent_total < 70)
  144. {
  145. record.letter_grade = 'D';
  146. }
  147. else
  148. {
  149. record.letter_grade = 'F';
  150. }
  151. }
  152.  
  153.  
  154.  
  155. void show_results(student& record)
  156. {
  157. cout << "Summary:" << endl;
  158. cout << "ID number:";
  159. cout << record.student_num << endl;
  160. cout << "Name:";
  161. cout << record.name_first <<" "<< record.name_last << endl;
  162. cout << "Quiz #1 score:";
  163. cout << record.quiz_1 << endl;
  164. cout << "Quiz #2 score:";
  165. cout << record.quiz_2 << endl;
  166. cout << "Midterm exam score:";
  167. cout << record.mid_exam << endl;
  168. cout << "Final exam score:";
  169. cout << record.final_exam << endl;
  170. cout << "Total points earned:";
  171. cout << record.total_points << endl;
  172. cout << "Percent Total:";
  173. cout << record.percent_total << "%" << endl;
  174. cout << "Grade:";
  175. cout << record.letter_grade << endl;
  176. }
  177.  
  178. void class_avg(int i, int temp1, int temp2, int temp3)
  179. {
  180. char avg_grade;
  181. double avg_percent;
  182. int highest;
  183. int lowest;
  184. int avg_score;
  185. avg_score = (temp1 + temp2 + temp3)/3;
  186. avg_percent = ((temp1 + temp2 + temp3)/6);
  187.  
  188.  
  189. cout << "Number of students processed: " << i << "\n";
  190.  
  191.  
  192. if (temp1 > temp2 && temp1 > temp3)
  193. {
  194. highest = temp1;
  195. cout << "Highest total points achieved: " << highest << "\n";
  196. }
  197. else if (temp2 > temp1 && temp2 > temp3)
  198. {
  199. highest = temp2;
  200. cout << "Highest total points achieved: " << highest << "\n";
  201. }
  202. else if (temp3 > temp1 && temp3 > temp2)
  203. {
  204. highest = temp3;
  205. cout << "Highest total points achieved: " << highest << "\n";
  206. }
  207.  
  208.  
  209. if (avg_percent >=90)
  210. {
  211. avg_grade = 'A';
  212. }
  213. else if (avg_percent >= 80 && avg_percent < 90)
  214. {
  215. avg_grade = 'B';
  216. }
  217. else if (avg_percent >= 70 && avg_percent < 80)
  218. {
  219. avg_grade = 'C';
  220. }
  221. else if (avg_percent >= 60 && avg_percent < 70)
  222. {
  223. avg_grade = 'D';
  224. }
  225. else
  226. avg_grade = 'F';
  227.  
  228.  
  229.  
  230. if (temp1 < temp2 && temp1 < temp3)
  231. {
  232. lowest = temp1;
  233. cout << "Lowest total points achieved: " << lowest << "\n";
  234. }
  235. else if (temp2 < temp1 && temp2 < temp3)
  236. {
  237. lowest = temp2;
  238. cout << "Lowest total points achieved: " << lowest << "\n";
  239. }
  240. else if (temp3 < temp1 && temp3 < temp2)
  241. {
  242. lowest = temp3;
  243. cout << "Lowest total points achieved: " << lowest << "\n";
  244. }
  245.  
  246. cout << "Average total points achieved: " << avg_score << "\n";
  247. cout << "Average letter grade achieved: " << avg_grade << "\n";
  248. cout << temp1 << endl << temp2 << endl << temp3;
  249. }
Last edited by mcap61; Oct 20th, 2009 at 7:40 pm.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 12
Reputation: mcap61 is an unknown quantity at this point 
Solved Threads: 0
mcap61 mcap61 is offline Offline
Newbie Poster
 
0
  #10
Oct 20th, 2009
OK I almost got it!
The only problem is that my student total score 3 shows up as zero.
  1. //Marc Capul
  2. //10/14/09
  3. //10/14/09
  4. //CISC 192 C/C++ Programming
  5. //Prof. Johnson
  6. //Assignment 3
  7. // WEEK 9
  8.  
  9. #include <iostream>
  10. using namespace std;
  11.  
  12. int n=0;
  13. double temp_1, temp_2, temp_3, avg;
  14. struct student
  15. {
  16. string name_first, name_last;
  17. char letter_grade;
  18. double student_num, quiz_1, quiz_2, mid_exam, final_exam;
  19. double total_points;
  20. double percent_total, class_total, class_avg;
  21. };
  22.  
  23. void get_data(student&);
  24. void calc_grade(student& record);
  25. void show_results(student& record);
  26. void class_avg(int i, double temp1, double temp2, double temp3);
  27.  
  28.  
  29. int main()
  30. {
  31. char ans;
  32. student record1, record2, record3;
  33. {
  34. n++;
  35. get_data(record1);
  36. temp_1 = record1.total_points;
  37. calc_grade(record1);
  38. show_results(record1);
  39. cout << "Is there another student's scores that need to be processed?";
  40. cout << endl;
  41. cout << "Press 'y' or 'Y' for yes or 'n' for Class Summary.";
  42. cin >> ans;
  43. }
  44. while (ans == 'y' || ans == 'Y')
  45. {
  46. n++;
  47. get_data(record2);
  48. temp_2 = record2.total_points;
  49. calc_grade(record2);
  50. show_results(record2);
  51. cout << "Is there another student's scores that need to be processed?";
  52. cout << endl;
  53. cout << "Press 'y' or 'Y' for yes or 'n' for Class Summary.";
  54. cin >> ans;
  55. }
  56. while (ans == 'y' || ans == 'Y')
  57. {
  58. n++;
  59. get_data(record3);
  60. temp_3 = record3.total_points;
  61. calc_grade(record3);
  62. show_results(record3);
  63. cout << "Is there another student's scores that need to be processed?";
  64. cout << endl;
  65. cout << "Press 'y' or 'Y' for yes or 'n' for Class Summary.";
  66. cin >> ans;
  67. }
  68. class_avg(n, temp_1, temp_2, temp_3);
  69. system("PAUSE");
  70. return 0;
  71. }
  72.  
  73. void get_data(student& record)
  74. {
  75. cout << "Please enter the following:\n";
  76. cout << "Student ID number:";
  77. cin >> record.student_num;
  78. while (record.student_num < 1 || record.student_num > 99999)
  79. {
  80. cout << "Invalid Student ID number.\n";
  81. cout << "Please enter again.\n";
  82. cin >> record.student_num;
  83. }
  84. cout << "First name:";
  85. cin >> record.name_first;
  86. cout << "Last name:";
  87. cin >> record.name_last;
  88. cout << "Quiz #1 score:";
  89. cin >> record.quiz_1;
  90. while (record.quiz_1 < 0 || record.quiz_1 > 25)
  91. {
  92. cout << "Invalid quiz score.\n";
  93. cout << "Please enter again.\n";
  94. cin >> record.quiz_1;
  95. }
  96. cout << "Quiz #2 Score:";
  97. cin >> record.quiz_2;
  98. while (record.quiz_2 < 0 || record.quiz_2 > 25)
  99. {
  100. cout << "Invalid quiz score.\n";
  101. cout << "Please enter again.\n";
  102. cin >> record.quiz_2;
  103. }
  104. cout << "Midterm exam score:";
  105. cin >> record.mid_exam;
  106. while (record.mid_exam < 0 || record.mid_exam > 50)
  107. {
  108. cout << "Invalid exam score.\n";
  109. cout << "Please enter again.\n";
  110. cin >> record.mid_exam;
  111. }
  112. cout << "Final exam score:";
  113. cin >> record.final_exam;
  114. while (record.final_exam < 0 || record.final_exam > 100)
  115. {
  116. cout << "Invalid exam score.\n";
  117. cout << "Please enter again.\n";
  118. cin >> record.final_exam;
  119. }
  120. record.total_points = (record.quiz_1 + record.quiz_2 + record.mid_exam + record.final_exam);
  121. }
  122.  
  123. void calc_grade(student& record)
  124. {
  125. char letter_grade;
  126. record.total_points = (record.quiz_1 + record.quiz_2 + record.mid_exam + record.final_exam);
  127.  
  128.  
  129. record.percent_total = (100)*((record.quiz_1 + record.quiz_2 + record.mid_exam + record.final_exam)/200);
  130.  
  131.  
  132. if (record.percent_total >= 90)
  133. {
  134. record.letter_grade = 'A';
  135. }
  136. else if (record.percent_total >= 80 && record.percent_total < 90)
  137. {
  138. record.letter_grade = 'B';
  139. }
  140. else if (record.percent_total >= 70 && record.percent_total < 80)
  141. {
  142. record.letter_grade = 'C';
  143. }
  144. else if (record.percent_total >= 60 && record.percent_total < 70)
  145. {
  146. record.letter_grade = 'D';
  147. }
  148. else
  149. {
  150. record.letter_grade = 'F';
  151. }
  152. }
  153.  
  154.  
  155.  
  156. void show_results(student& record)
  157. {
  158. cout << "Summary:" << endl;
  159. cout << "ID number:";
  160. cout << record.student_num << endl;
  161. cout << "Name:";
  162. cout << record.name_first <<" "<< record.name_last << endl;
  163. cout << "Quiz #1 score:";
  164. cout << record.quiz_1 << endl;
  165. cout << "Quiz #2 score:";
  166. cout << record.quiz_2 << endl;
  167. cout << "Midterm exam score:";
  168. cout << record.mid_exam << endl;
  169. cout << "Final exam score:";
  170. cout << record.final_exam << endl;
  171. cout << "Total points earned:";
  172. cout << record.total_points << endl;
  173. cout << "Percent Total:";
  174. cout << record.percent_total << "%" << endl;
  175. cout << "Grade:";
  176. cout << record.letter_grade << endl;
  177. }
  178.  
  179. void class_avg(int i, double temp1, double temp2, double temp3)
  180. {
  181. char avg_grade;
  182. double avg_percent;
  183. double highest, lowest;
  184. double avg_score;
  185. avg_score = ((temp1 + temp2 + temp3)/(n));
  186. avg_percent = ((temp1 + temp2 + temp3)/ (2*i));
  187.  
  188.  
  189. cout << "Number of students processed: " << i << "\n";
  190.  
  191.  
  192. if (temp1 > temp2 && temp1 > temp3)
  193. {
  194. highest = temp1;
  195. cout << "Highest total points achieved: " << highest << "\n";
  196. }
  197. else if (temp2 > temp1 && temp2 > temp3)
  198. {
  199. highest = temp2;
  200. cout << "Highest total points achieved: " << highest << "\n";
  201. }
  202. else if (temp3 > temp1 && temp3 > temp2)
  203. {
  204. highest = temp3;
  205. cout << "Highest total points achieved: " << highest << "\n";
  206. }
  207.  
  208.  
  209. if (avg_percent >=90)
  210. {
  211. avg_grade = 'A';
  212. }
  213. else if (avg_percent >= 80 && avg_percent < 90)
  214. {
  215. avg_grade = 'B';
  216. }
  217. else if (avg_percent >= 70 && avg_percent < 80)
  218. {
  219. avg_grade = 'C';
  220. }
  221. else if (avg_percent >= 60 && avg_percent < 70)
  222. {
  223. avg_grade = 'D';
  224. }
  225. else
  226. avg_grade = 'F';
  227.  
  228.  
  229.  
  230. if (temp1 < temp2 && temp1 < temp3)
  231. {
  232. lowest = temp1;
  233. cout << "Lowest total points achieved: " << lowest << "\n";
  234. }
  235. else if (temp2 < temp1 && temp2 < temp3)
  236. {
  237. lowest = temp2;
  238. cout << "Lowest total points achieved: " << lowest << "\n";
  239. }
  240. else if (temp3 < temp1 && temp3 < temp2)
  241. {
  242. lowest = temp3;
  243. cout << "Lowest total points achieved: " << lowest << "\n";
  244. }
  245.  
  246. cout << "Average total points achieved: " << avg_score << "\n";
  247. cout << "Average letter grade achieved: " << avg_grade << "\n";
  248. cout << temp1 << endl << temp2 << endl << temp3;
  249. }
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC