# Thread: Help! calculating grades

1. ## Help! calculating grades

No matter which grade, the final letter grade is "F"

please tell me where I've got it wrong

Code:
```#include<iostream>
02 using namespace std;
03
04 struct record
05 {
06 double quiz1;
07 double quiz2;
08 double midyear, midyear_one;
09 double final, final_one;
10 double quiz_average;
11 char final_grade;
12 double total_grade;
13 };
14 void instructions();
15 void input(record& the_grades);
16 void output(record& the_grades);
17
18 int main()
19 {
20 record grades;
21 instructions();
22 input(grades);
23 output(grades);
24 cout << endl << endl;
25 cout << "<program end>";
26 cout << endl << endl;
27 system("pause");
28 return 0;
29 }
30
31 void instructions()
32 {
33 cout << "Welcome to the program student record";
34 cout << endl << "this program takes in 2quizes, a final and midyear";
35 cout << endl << "and then calculates the average by what they are worth by";
36 cout << endl << "the quizes together are worth 25% and midyear counts for 25%";
37 cout << endl << "and the final counts for 50%";
38 cout << endl;
39 }
40 void input(record& the_grades)
41 {
42 cout << "Enter quiz1 grade out of 10 points:\n";
43 cin >> the_grades.quiz1;
44 cout << endl;
45 cout << "Enter quiz2 grade out of 10 points:\n";
46 cin >> the_grades.quiz2;
47 cout << "Enter midyear Exam grade out of 100 points:\n";
48 cin >> the_grades.midyear;
49 cout << endl;
50 cout << "Enter Final Exam grade out of 100 points:\n";
51 cin >> the_grades.final;
52 cout << endl;
53 }
54 void output(record& the_grades)
55 {
56 the_grades.quiz_average = (((the_grades.quiz1/10) + (the_grades.quiz2/10))/2) * .25;
57 the_grades.final_one = (the_grades.final/100) * .5;
58 the_grades.midyear_one = (the_grades.midyear/100) *.25;
59 the_grades.total_grade = the_grades.quiz_average + the_grades.final_one + the_grades.midyear_one;
60
61 cout << endl << endl;
62 cout <<"Quiz1: "<< the_grades.quiz1 <<"/10";
63 cout << endl;
64 cout <<"Quiz2: "<< the_grades.quiz2 <<"/10";
65 cout << endl;
66 cout <<"Midyear exam: " << the_grades.midyear<<"/100";
67 cout << endl;
68 cout <<"Final exam: " << the_grades.final<<"/100";
69 cout << endl;
70 cout <<"Final grade: "<< the_grades.total_grade*100;
71 cout << endl;
72 cout <<"Letter grade: ";
73 if(the_grades.total_grade < 60)
74 {
75 cout << "F";
76 }
77 if((the_grades.total_grade > 60)&&(the_grades.total_grade < 70))
78 {
79 cout << "D";
80 }
81 if((the_grades.total_grade > 70)&&(the_grades.total_grade < 80))
82 {
83 cout << "C";
84 }
85 if((the_grades.total_grade > 80)&&(the_grades.total_grade < 90))
86 {
87 cout << "B";
88 }
89 if(the_grades.total_grade > 90)
90 {
91 cout << "A";
92 }
93 cout << endl;
94
95
96 }```

2. Well you could edit your post so that your code isn't double-numbered and double-spaced.

Then people will be more inclined to read it.

3. Originally Posted by Salem
Well you could edit your post so that your code isn't double-numbered and double-spaced.

Then people will be more inclined to read it.
done it

4. Originally Posted by anlk5910
done it
Sooooo..... eerrrrrr

You might want to post the new code without all the numbers and with the proper indentation, just so, you know, we can see it?

5. > cout <<"Final grade: "<< the_grades.total_grade*100;
What does this print?
And what does that mean for the original value of total_grade, when it comes to all your comparisons.

BTW, what happens if you have == 80 for example?

6. I figured it out

7. Share your answer so the rest of the world might benefit from your knowledge.

8. It seems the maximum your total grade sum can be is 1, so try dividing the testing conditions by 100.

This code in particular needs to be changed,

cout <<"Letter grade: ";
73 if(the_grades.total_grade < 60)
74 {
75 cout << "F";
76 }
77 if((the_grades.total_grade > 60)&&(the_grades.total_grade < 70))
78 {
79 cout << "D";
80 }
81 if((the_grades.total_grade > 70)&&(the_grades.total_grade < 80))
82 {
83 cout << "C";
84 }
85 if((the_grades.total_grade > 80)&&(the_grades.total_grade < 90))
86 {
87 cout << "B";
88 }
89 if(the_grades.total_grade > 90)
90 {
91 cout << "A";
92 }

Popular pages Recent additions