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;
}

Anyone??

In the function displayAverage():

change total = total + inputP[i][j]; to : total = total + inputP[j][i]; j runs from 0 to NR_FRIENDS and
i runs from 0 to NR_MODULES
Your array is declared as const int inputP[] [NR_MODULES] So you can see that you switched the two variables :)
Small typo, big consequence

also read this about codeformatting

[edit]

Anyone??

That's very impolite... Bumping after half an hour (or even bumping in general) makes me not want to help people. So you're lucky I already wrote this reply and I'm not deleting it...

HA HA HA HA , I can bearly believe it was something so simple , thanks very much works great now :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.