#include <iostream>
using namespace std;
void main ()
{
int exam[10][10];
int ave[10];
int x, y;
int sum;
cout<<"Input number of Subjects ";
cin>>x;
cout<<"Input of number of exams per subjects ";
cin>>y;
for (int i = 1 ; i <= x ; i++)
for (int j = 1 ; j <= y ; j++)
{
cout<<"Subject "<<i<<endl;
cout<<"Input grades on Exam "<<j<<" ";
cin>>exam[x][y];
}
for(int i=0; i<x; i++)
{ sum=0;
for(int j=0; j<y; j++)
{
sum +=exam[x][y];
}
ave[y] = sum/y;
cout<<"subject "<<i+1<<"average is "<<ave[y];
cout<<endl;
}
system ("pause");
}
This is obviously the wrong code.
The output should be the average of the exam per subject. Which is I don't know how to do it. Help please?
it is
exam[i][j]
not exam[x][y]
the same for
ave[i]
not ave[y]
an array starts with 0. hence the loop is supposed to be
1 2

for (int i = 0 ; i < x ; i++)
for (int j = 0 ; j < y ; j++)

[EDIT]
if you want start with 1 in your cout just put
i + 1
etc
Last edited on
Your indexes are inconsistent.
That's the only problem.. It worked now.:/ Thanks guys. xD