Hi all , I have a program I have written for a question , but it has one problem I dont seem to be able to solve , the last part has to calculate the average hours spent on each module , yet it keeps coming up with answers I cant see where its getting, Please Help , Here is the code below:
include <iostream>
using namespace std;
const int NR_FRIENDS = 4;
const int NR_MODULES = 3;
void getdata(int inputP[] [NR_MODULES])
{ int friends;
for (int i = 0;i < NR_FRIENDS; i++)
{friends = i + 1;
{ cout << "Enter the hours for the " << NR_MODULES << " modules studied weekly for friend " << friends << endl;
for (int j = 0;j < NR_MODULES;j++)
{
cin >> inputP[i][j];
}
}
}
}
void showdata(const int inputP[] [NR_MODULES])
{ string friends;
string name[4]={"Aggie","Bruce","Cecil","Danita"};
cout <<'\t'<< "ABC111"<<'\t'<< "DEF222"<<'\t'<< "GHI333";
cout << endl;
//rows.
for (int i = 0;i < NR_FRIENDS;i++)
{ cout << name[i];
for (int j = 0;j < NR_MODULES;j++)
cout <<'\t'<< inputP[i][j];
cout << endl;
}
}
void displayAverage (const int inputP[] [NR_MODULES])
{ int total;
float average;
cout << "the average of each module is : " << endl;
for (int i = 0;i < NR_MODULES;i++)
{ total = 0;
cout << "Module " << i+1 << " : ";
for (int j = 0;j < NR_FRIENDS;j++)
total = total + inputP[i][j];
average = float(total) / NR_FRIENDS;
cout << average << endl;
}
}
int main ()
{ int input[NR_FRIENDS][NR_MODULES];
getdata(input);
showdata(input);
cout << endl;
displayAverage(input);
return 0;
}