Checkpoint 14.8.1.
In ListingΒ 14.8.2, we want to calculate an average of the temperature at each depth level. To do that, we need to declare a `total` variable to accumulate the sum of temperatures at each depth. Where should we add
double total = 0;?
// Spot A
for (size_t depth = 0; depth < depthCount; ++depth) {
cout << "Depth " << depth << ":" << endl;
// Spot B
for (size_t lat = 0; lat < latitudeCount; ++lat) {
// Spot C
for (size_t lon = 0; lon < longitudeCount; ++lon) {
// Spot D
cout << oceanTemps.at(depth).at(lat).at(lon) << " ";
total += oceanTemps.at(depth).at(lat).at(lon);
}
cout << endl;
// Spot E
}
// Spot F
cout << "---------------------" << endl;
}
// Spot G
- Spot A
- If we declare
totalhere, it will accumulate values from all depth levels. We want to reset it for each depth. - Spot B
- Spot C
- If we declare
totalhere, it will reset for each latitude, which is not what we want. - Spot D
- If we declare
totalhere, it will reset for each longitude, which is not what we want. - Spot E
- Spot F
- Spot G
