Need help with output. Beginner at programming.

Hi I am new to this forum and also a beginner at programming. I just want to ask some help for those kind people out there about my code. I am getting an output of the average of the 4 exams of 5 students. My problem is, i don't know how to get the output for the average of each exam. e.g average of exam # 1 of 5 students. Thanks for helping me out!

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

 main()
{
	float grades[5][4],sum[5],avg[4],sum_exam[5],ave_exam[4];
	int sumR1=0;
	
	cout<<"\t\tGRADING SHEET OF STUDENTS"<<endl;
	
	for (int student=0 ; student<=4 ; student++)
	{
		cout<<"\nEnter grades of student # "<<student+1<<": "<<endl;
		
		for (int exam=0 ; exam<=3 ;exam++)
		{
			cout<<"Exam number "<<exam+1<<": ";
			cin>>grades[student][exam];
		}
	}
	
	for (int student=0 ; student<=4 ; student++)
	{
		sum[student]=0;
		avg[student]=0;
		
		for (int exam=0; exam<=3; exam++)
		{
			sum[student] += grades[student][exam];
			
		}
			avg[student] += sum[student]/4;
	}
			cout<<endl;
		
	for (int ave=0; ave<=4; ave++)
	{
		cout<<"The average of student # "<<ave+1<<": "<<avg[ave]<<endl;
	}
	
	system ("pause");
}
Your data is in a 2D table. The results for one student are all on the same row of the table. You do calculate the average for each row. You do calculate the sum for a row, don't you?

The results for an exam are on the same column. Calculate sum for a column.
closed account (48T7M4Gy)
1
2
3
4
5
6
7
8
9
10
11
12
13
	
        for (int exam=0 ; exam<=3 ; exam++)
	{
		// Insert code to set zero values for average totals

                for (int student=0 ; student<=4 ;student++)
		{
			// Insert code to calculate totals for all students for each exam;
		}
                
                // Insert code to calculate average and display it for current exam

	}
Last edited on
Topic archived. No new replies allowed.