making a function

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 help me correct this please
Last edited on
psuedo code:

1
2
3
4
5
6
7
int scaleData( yourArray, scaleFactor)
{
    // iterate over each element of the array
    element = element * scaleFacor

   // non-zero check and return here
}


when passing in your array pass it by reference.
Last edited on
is this all of it because i still dont understand it
Note the example above is pseudeo-code - that is it is written so a human being can follow the idea, the high-level structure, but the actual C++ code will look a bit different.

You could re-use some of the code from the example in this thread:
http://www.cplusplus.com/forum/beginner/119061/

i am still really confused on what to do
Well, if you don't mind my saying so, the best way to clear the confusion is to type your best attempt at the code into your editor, then compile and run it, and see what sort of results it gives. Then come back with your further questions depending upon how it works out.
Last edited on
I think this one is simple and the link provided to you is same.
Now tell me in which line you are facing problem?
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 do this look right if not what is it suppose to look like?
Topic archived. No new replies allowed.