@ lastchance, sorry I missed your last two posts last night.
I am assuming that you said the last code is worse than it was before because it is supposed to be a value returning function, and instead of returning it's using cout. Shows lack of understanding the concepts. I am seeing that now.
In reference to:
"(stoneJax) I am not clear on what you mean by, "(lastchance) if you want an average for each column then you will have to have an array for them (or use an extra row of the existing array)."
(lastchance) Please explain what you don't understand there."
I am new so I really have no idea where you are going with that statement. It sounds like you are saying to create another array to hold the new values or wipe out existing values in the same array to hold them, but I am not sure. If so, that is beyond the scope of what I have practiced.
I Took to Salem's approach today and turned the function into a void function and now it works perfectly. I'll post it below.
Although the function works and I am happy with it the way it is, I still want to learn why it didn't work as a return function. I am in a first course C++ class so the material is new and I am trying to solidify the information into memory and get consistent.
It seems that I am off on understanding exactly how to use a return function for this scenario. Lastchance asks "What SINGLE value do you wish to return?" Here, maybe this is the problem because I am not trying to return a single value but rather, an average for each column. Here is a posted example output.
1 2 3 4 5 6 7
|
Average Rating for each movie:
Movie#100: 3.75
Movie#101: 1.25
Movie#102: 3
Movie#103: 3
Movie#104: 2.75
Movie#105: 3
|
Here is my new code as a void function that works good.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
void calculateAverageRatings(const int array[][NUM_MOVIES])
{
int sum = 0;
double average = 0;
for(int col = 0; col < NUM_MOVIES; col++)
{ sum = 0;
for(int row = 0; row < NUM_REVIEWERS; row++)
{
sum = sum + array[row][col];
average = sum / NUM_MOVIES;
}
average = sum / 4.0;
cout << endl;
cout << "Movie#" << col + 100 << ": " << average;
}
cout << endl;
}
|