I have the whole code written for what I want to do, but the only problem is, on my Daily_Average function, I want to print the average of the scores occurring Day 3, but I'm getting average of ALL scores together as one. Here is an example of the scores etc.
..... Day 1 Day 2 Day 3
Jimmy 70 68 71
Jason 72 75 68
Roy 68 69 67
Griff 65 64 59
John 71 81 74
I want to get the average of the scores under the Day 3 column, but how do I do it? I tried everything. I'm getting the sum of all the numbers, but unfortunately, that is the only way I know how to get the sum. How do I get sum for the scores in Day 3 and not the whole thing? This is for "Daily_Average" function. Also, I need to return that average. Thanks!
#include <iostream>
#include <iomanip>
using namespace std;
void Prt_Gradebook (string names[], int score[][3]);
double Daily_Average (int score[][3], int day);
int Lowest_score (string names[], int score[][3]);
int main ()
{
string names[5] = {"Jimmy","Jason","Roy","Griff","John"};
int score[5][3] = {{70,68,71},{72,75,68},{68,69,67},{65,64,59},{71,81,74}};
int day;
Prt_Gradebook(names,score);
cout<<"The Average for Day 3 is "<<Daily_Average(score,day)<<endl;
Lowest_score(names,score);
cout<<endl;
system ("PAUSE");
return 0;
}
void Prt_Gradebook (string names[], int score[][3])
{
int sum = 0;
for (int i = 0; i < 5; i++)
{
cout<<names[i]<<" ";
for (int j = 0; j < 3; j++)
{
cout<<score[i][j]<<" ";
sum+=score[i][j];
}
cout<<sum;
cout<<endl;
}
}
double Daily_Average (int score[][3],int day)
{
double average;
int sum = 0;
int j = day-1;
for (int i = 0; i < 5; i++)
{
for (j = 0; j < 3; j++)
{
sum+=score[i][j];
average = (sum / 5);
}
}
return average;
}
int Lowest_score (string names[], int score[][3])
{
int lowest;
int day;
int j = day-1;
for (int i = 0; i < 5; i++)
{
for (j = 0; j < 3; j++)
if (score[i][j] < lowest)
lowest = score[i][j];
}
cout<<"Langon's lowest score of "<<lowest<<" was shot on day "<<j<<endl;
}