Thread: Code Flow (arrays and loops)

1. Code Flow (arrays and loops)

Hi: Thank you for taking time to help me with my problem. I am having problems understanding where this code is wrong as I believe that I am not receiving the correct outputs. I have truncated the code to the most pertinent.

The algorithm asks that every value in array1 be divided by array2
and if that value is less than the ratio * array3 (percentage filter) then output.

I have no problem with the code with the exception of
abs(ratio*array3[m]

Assuming that the ratio = 1 then all values get outputted, I want the array1 (first value) to have the first value in array3 assigned to it, the second value in array1 to have the second value in array3 to be assigned.

So:
array1 (1.0) with array3 (0.05)
array1 (2.0) with array3 (0.06)
etc.

Code:
```array1[5] = {1.0, 2.0, 3.0, 4.0, 5.0};
array2[5] = {1.0, 2.0, 3.0, 4.0, 5.0};
array3[5] = {0.05, 0.06, 0.07, 0.08, 0.09};

ratio = abc/def;

for(int m=0; m<5; m++)
{
for(int n=0; n<5; n++)
{
if(abs(ratio-array1[m]/array2[n])<abs(ratio*array3[m]))
{
>>then print out values paired matches of array1[] and array2[]
}```
Thank you again for pointing out any problem you see.

2. 1. Your arrays and variables (ratio, abc, def) must be floating-point type (float or double) to return requested value.
2. To use abs() function remember to include appropriate header file.

3. your code is not code

4. Thank you - I should have stated that it is pseudo code - I have the problem solved. Thanks for your help.

5. ok, i did think that - but it is best to indicate, we never know when someone is really far off the mark with their code.

Another thing i should say though is that the indentation style is really rather strange, and not very nice - i dont know if that is just the browser formatting but if not, sort it out.