# Thread: Multiplying numbers in an array

1. ## Multiplying numbers in an array

Hi,

I'm trying to write a code, where numbers in an array, are multiplied by another array of numbers.
In addition, once the multiplied array has reached its final number it has to loop again. Then continue multiplication till the array of of numbers have been multiplied.

Here's an example of what I mean:
5,5,7 -used for multiplication
1,2,1,2,2,1,1 -array of numbers

1x5, 2x5, 4x7,
2x5, 2x5, 1x7,
1x5

Here's my code: -it doesn't compile, but I'm trying to find a way to fix it
Code:
```int main()
{
int sample[] = {1,2,4,5,7,9,1};

filterSamples(sample);
return 0;
}

int filterSamples(int& samples[])
{
double countNumber = 0;
double filterNumbers[] = {2.5, 3.4, 5};
double *filterResults;

//filterResults = (double *) malloc(samples);

for(int i=0; i<samples.length(); i++)
{
filterResults = samples[i] * filterNumbers;

countNumber++;
}
//finalNumbers = filterSamples;
cout << "filtered: " << countNumber << ". " << filterResults << "\n" << endl;
return 0;
}```

2. You are doing a few things "funny":
Code:
```int main()
{
int sample[] = {1,2,4,5,7,9,1};

filterSamples(sample);
return 0;
}

int filterSamples(int& samples[])
{
double countNumber = 0;
double filterNumbers[] = {2.5, 3.4, 5};
double *filterResults;

//filterResults = (double *) malloc(samples);

for(int i=0; i<samples.length(); i++)
{
filterResults = samples[i] * filterNumbers;

countNumber++;
}
//finalNumbers = filterSamples;
cout << "filtered: " << countNumber << ". " << filterResults << "\n" << endl;
return 0;
}```
Filter results is a pointer. You are trying to assign a double to that pointer - this is invalid, and even if the compiler allowed it, wouldn't be what you wanted to do. Then you print your pointer, which is probably not what you wanted to do either.

The input "samples" is an array of integer. You are trying to get the length() from an array of integer. This doesn't work - you need a vector or similar template class to do that.

--
Mats