Thread: How to Calm Unruly [ARRAYS]

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    16

    How to Calm Unruly [ARRAYS]

    I am using a looped array in which a mathematical equation is derived. I have set the following:



    Code:
    int answer;
        
    answer = AnotherEquation * TheSecondEquation + AbunchOfOtherCrud
                    / ThisGetsPrettyComplicated;
    
     loop goes here:::::::::::
    
      if answer = array1[i]/array2[z]  
    
        {then do this}
    The problem is it is too sensitive. I would like to set ranges (+/- 5%) in order to find a ballpark or I would never get an answer.

    I would prefer to have the range set in the output from the array (for instance the higher the number the more range I would like -whereas the lower numbers would receive less range).

    Thanks to all! I appreciate you not letting me feel like a total C++ moron.

  2. #2
    The larch
    Join Date
    May 2006
    Posts
    3,573
    It is quite hard to tell anything. What exactly are you doing? What are array1 and array2? Where do you get i and z from etc.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    So, if the values are within 5 percent, array1[i]/array2[z] should be between 0.95 and 1.05.

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Take the absolute of the difference, convert it to floating point, divide by the original value and see if the result is <= 0.05.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed