// bigger, a, and b are parallel arrays.
// function's job is to set each element of big to larger of
// the corresponding element of a and the corresponding element of b.
// all 3 arrays are the same size, each having els elements.
// For example, if a held {1, 2, 3, 4, 5, 6, 7} and b held {10, 8, 6, 4, 2, 0, -2},
// and bigger were an array of 7 doubles, then
// then setBigger( bigger, a, b, 7 ) would set the array bigger to hold
// {10, 8, 6, 4, 5, 6, 7}
void setBigger( double bigger[], const double a[], const double b[], unsigned els );
These are the instructions for our last homework assignment of the semester. He JUST taught us how to use arrays so I am still a big confused on how to do this.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
void setBigger(double bigger[], const double a[], const double b[], unsigned els) {
double big = 0;
for (unsigned pos = 0; pos < els; pos++){
double big = 0;
for (unsigned pos1 = 0; pos1 < els; pos++) {
if (a[pos1] > big) {
big = a[pos1];
bigger[pos] = a[pos1];
}
if (b[pos1] > big) {
big = b[pos1];
bigger[pos] = b[pos1];
}
}
}
|
This is what I have so far. The problem I have with my current code is that it will set all positions in the array bigger[] to the largest number in a[] and b[].
Any suggestions on how to make sure it doesn't read the last character it copied into the array bigger[] ?
All help is appreciated! (please no direct answers. Just guidance)