Compute the average of weighted exams

This is a hw assignment and I've been stuck on this for a week and could use some guidance on this.

This is the hw description so you get an understanding of what is suppose to happen: Suppose a teacher weights the four
exams he gives 10%, 25%, 30%, and 35%. Write a
program that reads ten sets of four grades, prints the
weighted average of each set, and prints the unweighted
average of each test. The number of students should be
in a global constant.

*As of right now I am setting up the program to read 4 sets of four grades just so I can run the program a bit faster.

The program needs just one loop and no arrays.

So this is my problem. Say I enter 60, 70, 80, and 90 for the cin prompt, the program adds them together and divides by 4.0 giving an answer of 75. What I'm trying to do is put 60 into the grades call for exam1, 70 into exam2 and so on. When added together total should be equal to 79 and the average should come out to 19.75. So im stuck as to why the program is adding the cins instead of assigning them to their appropriate exam to be calculated.

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
 #include <iostream>
using namespace std;

int main ()
{
	int i;
	double total, average, grades, exam1, exam2, exam3, exam4;

	total = 0;

	for (i = 1; i <= 4; i++)
	{
		cout<<"Enter the four grades:"<<endl<<endl;
		cin>>grades;
		cout<<endl<<endl;
		
		exam1 = grades*.10;
		exam2 = grades*.25;
		exam3 = grades*.30;
		exam4 = grades*.35;
		
		total = total+exam1+exam2+exam3+exam4;
	}

	
	
	average = total/4.0;
	cout<<"average is "<<average<<endl<<endl;

	
	
	//system ("pause");
	return 0; 
}
1
2
3
4
5
6
7
8
9
10
11
12
13
exam1 = grades*.10;
exam2 = grades*.25;
exam3 = grades*.30;
exam4 = grades*.35;
		
total = total+exam1+exam2+exam3+exam4;

<=>
total = total + grades*.10 + grades*.25 + grades*.30 + grades*.35;
<=>
total = total + grades*( .10 + .25 + .30 + .35 );
<=>
total = total + grades;

Each iteration of your loop takes exactly one value from user and adds it to the total. That is clearly not what you think it is doing.
Topic archived. No new replies allowed.