Having trouble computing students weighted course grade


I am suppose to create a program to compute a students weighted course grade but I am not getting the results I want and the the program to display how I want it to. Below is the intstructions for the project along with how it is suppose to output when ran but when I debug my code and run it it does not compute the overall average how I want it. when I use the numbers given in the example to test the program it outputs an overall grade of 94.4 instead of the average 80.93. I also for some reason can't get the percent sign to show. I am missing a step but not sure where..I knwo that 101/150 is 67 which is the number needed to get 80.93 . which tells me that I have to get the scorees divded by the maximum points on test but no matter how many different timesI write it it does not out put what I want or perform that action.



Write a program to compute a student's weighted course score. There are three tests in the class. The user should enter the maximum points for each test (they do not have to be the same) (integer), the student's score on each test (integer), and the weight of each test (as a percent of 1.0 (0.4 = 40%)) (floating-point value). Your code should output the student's weighted course grade.

Example 1:

Weight of first test: 30
Maximum on first test: 100
Score on first test: 93

Weight of second test: 30
Maximum on second test: 100
Score on second test: 87

Weight of third test: 40
Maximum on third test: 150
Score on third test: 101

Your overall grade is 80.93%



#include <iostream>
#include <string>

using namespace std;

int main()
{




int score1 = 0;
int score2 = 0;
int score3 = 0;
int test1 = 0;
int test2 = 0;
int test3 = 0;
double weight1 = 0;
double weight2 = 0;
double weight3 = 0;
double weight = 0;



cout << "Weight of first test:";
cin >> weight1;

cout << "Maximum on first test:";
cin >> test1;

cout << "score on first test:";
cin >> score1;





cout << "Weight of second test:";
cin >> weight2;

cout << "Maximum on second test:";
cout >> test2;

cout << "Score on first test:";
cin >> score2;






cout << "Weight of third test:";
cin >> weight3;

cout << "Maximum on third test:";
cin >> test3;

cout << "score3 on first test:";
cin >> score3;



weight = score1* weight1 + score2 * weight2 + score3 * weight3;

cout << " Your overall grade is " << weight << "\n";

system ("pause");
return 0;



}







Remy JDH

Try this slight alteration of your code in the final expression.
You were so close!
I only put the
cout<<endl;
bits in to separate out the 3 tests.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
using namespace std;
int main()
{
int score1 = 0;
int score2 = 0;
int score3 = 0;
int test1 = 0;
int test2 = 0;
int test3 = 0;
double weight1 = 0;
double weight2 = 0;
double weight3 = 0;
double weight = 0;

cout << "Weight of first test: ";
cin >> weight1;
cout << "Maximum on first test: ";
cin >> test1;
cout << "Score on first test: ";
cin >> score1;
cout<<endl;

cout << "Weight of second test: ";
cin >> weight2;
cout << "Maximum on second test: ";
cin >> test2;
cout << "Score on second test: ";
cin >> score2;
cout<<endl;

cout << "Weight of third test:";
cin >> weight3;
cout << "Maximum on third test:";
cin >> test3;
cout << "Score on third test: ";
cin >> score3;
cout<<endl;
weight = score1*weight1/test1 + score2*weight2/test2 + score3*weight3/test3;
cout << "Your overall grade is " << weight*100 << "%\n";

cin.get ();
cin.get ();
return 0;
}

You had a couple of minor typos, but the fix is to divide each expression at the end by the max score. Try it out on a bit of paper with your calculator and you'll soon see it!
To convert a decimal to a percentage just multiply by 100.
Best wishes, Don from down under.

Last edited on
thanks for the enlightement. I can't believe I was missing the /test .. I knew something was off. also thaks for showing me how seperate with cou<< endl; I was baffled for a while in doing so.. I can now apply that to my other project lol. apprecciate you taking the time to help put.
Topic archived. No new replies allowed.