Compute the average of weighted exams.

I need help on my CSCI-40 assignment. Here is what is asked of me: 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. So far I am able to read 4 exams 10 times. I need to print the weighted average of each set. Here is my work so far:


#include <iostream>
using namespace std;
const int totalValues=10;
int main()
{
double total, waverage, grades, exam1, exam2, exam3, exam4, i;
total=0;
for(i=1;i<=totalValues;i++)
{
cout<<"Enter the exams: "<<endl;
cin>>exam1>>exam2>>exam3>>exam4;
total+=grades;
}
}
For weighted average, don't code it until you know how to do it by hand. Then
1
2
cin >> exam1 >> exam2 >> exam3 >> exam4;
cout << "Weighted average is" << [put your calculation here] << '\n';



If you require an average for each exam then you will have to add them up as you receive new exam data in the loop, so:
- declare variables to hold the totals for each exam and initialise these to 0
- when you enter a new exam mark add this to the appropriate total
- when you have finished reading all data divide the total for each exam by totalValues and print it out.


Your loop variable should not be a double. Remove the declaration of i as a double and instead declare it in the for statement:
for ( int i = 1; i <= totalValues; i++ )


Please use code tags.

Topic archived. No new replies allowed.