creating this array

i have to write a function called scaleData that accepts an array of doubles and a double named scaleFactor. The function must multiple each element of data by the scaleFactor which must be non-zero. if the scale factor in non-zero, return 0; otherwise return 1 (an error code of sorts)

double scaleData( int scaleFactor, int arraySize)
{
double sum = 0;
for (int i = 0; i < arraySize; i++)
sum = sum*scaleFactor;

return 0;
}
this is what i have will someone show me what it is suppose to look like thanks i really need help on this
1. You didn't pass the array into your function.
2. Your scaleFactor variable wasn't a double as indicated by the directions.
3. I might be mistaken, but I believe the function is supposed to simply multiply each index of the array by the scaleFactor so as to do what the function name says: Scale the data. An array is automatically pass by reference, so whenever you modify the values inside of the array inside of this function, the original array is modified as well.
4. You didn't check to see if the scaleFactor was non-zero or not as per the instructions.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// Here we are passing our double array into the function as well as the
// scaleFactor double.
int scaleData(double array[], int arraySize, double scaleFactor)
{
    // Check to see if the scaleFactor is 0. If so, exit function.
    if (scaleFactor == 0)
        return 1;
    
    // Increment through the array and scale each value inside by the scaleFactor.
    for (int i = 0; i < arraySize; ++i)
        array[i] *= scaleFactor;
    
    // Success! Return 0!
    return 0;
}
Topic archived. No new replies allowed.