0

I'm currently trying to solve a programming problem that involves different ranges of values that overlap. The task is to accept input, in E-notation, and that is where the overlap of range inevitably occurs.

I have 2 ranges that overlap at 1E-11. 1E-11 and lower and 1E-11 and higher The output would be 1E-11 is either x or it is y. Programmatically i would solve it like this:

(X_MIN would be 1E-11 and X_MAX 1E-8)
(Y_MAX would be 1E-11 and Y_MIN 1E-13)

(lengthOfRange <= X_MIN) && (lengthOfRange >= Y_MAX) ? 
cout << "This value entered indicates that it is x\n" :
cout << "It is y";

Expressed this way if i input IE-11 it shows me "This value entered indicates ..." but will never show me it is y (understandably - overlap!)

The other way around would be expressing it this way:

(lengthOfRange <= X_MIN) && (lengthOfRange != Y_MAX) ? 
cout << "This value entered indicates that it is x\n" :
cout << "It is y";

The output would always be "... It is y ..." (Same difference - overlap!) There is no other determining factor that would tell range is x or y coming in to play there as of right now.

...
if (lengthOfRange <= X_MIN) && (lengthOfRange == Y_MAX)
{
   cout << "The input indicates that it could be either x or y\n";
}
...

Even if i were to solve the problem in a way such as defining the range with different values, would in the end lead to the very same problem. I COULD define MIN and MAX as constants in lengthOfFrequency, which is totally different, bit then i would have to say: lengthOfFrequency = 1E-11; and voila same problem once again. 1 input 2 ranges that are technically different, getting the same one and only correct value in E-notation.

Is there a way around this without involving to simply say input is either x || y? Which it is technically of course, and if it were to be solved physically there are ways of telling it apart that 1E-11 is not 1E-11 though it is. (I hope i make sense here). But, again, ... is there such way, and how would i go about writing it? (Not asking for code specifically though it would be highly welcome, just a pointer in the right direction.) Or should i rather go with saying input is either x || y?

Thanks in advance for any answer!

**Minimum Complete Code:** 

   #include <iostream>

using std::cout;
using std::cin;

int main()
{
    /* Constants for ranges, min and max */
    const double X_RAYS_MIN = 1E-13,
                 X_RAYS_MAX = 1E-11,
                 Y_RAYS_MIN = 1E-11,
                 Y_RAYS_MAX = 1E-8,
                 Z_RAYS_MIN = 1E-7,
                 Z_RAYS_MAX = 3.8E-7;

    double lengthOfRange;

    /* Test output and validation */
    cout << "Enter value in scientifc notation: ";
    cin >> lengthOfRange;

    /* X_RAYS_MIN < is 1E-14, 1E-15, 1E-16 etc. > 1E-12, 1E-11 etc.. */
    if (lengthOfRange >= X_RAYS_MIN && lengthOfRange <= X_RAYS_MAX)
    {
        cout << "X_RAYS\n";
    }
    else if (lengthOfRange >= Y_RAYS_MIN && lengthOfRange <= Y_RAYS_MAX)
    {
        cout << "Y_RAYS\n";
    }

    system("pause");
    return 0;
}

Output is: 1E-10 is Y_RAYS, 1E-9 is Y_RAYS, 1E-11 X_RAYS, 1E-12 X_RAYS

Somehow i found the solution for my problem myself without going any roundabout ways ... By hovering over the 1E-13:

X_RAYS_MIN = 1E-13

VS showed me 1.(numberofzeros)3E-13, and guess what ... if instead the input for 1E-11 is 2E-11, the output for X_RAYS becomes Y_RAYS ... so the problem "magically" solved itself ... lucky me i guess ... :)

Yuki Mori
  • 1
  • 1
  • 2
  • The answer completely depends on how you want to handle that case. Are those interval supposed to be disjoint? Then treat them as such. You have to decide whether the boundary point belongs to the upper or to the lower interval. Most simple would be to use halfopen interval, ie `bool ValbelongsToX = (Val >= xmin && Val < xmax)` – 463035818_is_not_an_ai Nov 23 '16 at 12:33
  • First of all thank you for your proposed solution and answer! The intervals are indeed disjoint in a way. They are overlapping only in the sense that x and y share a common boundary value at some points, one of them is: 1E-11. Where the one ends, the other starts. I do see how your solution fits into solving one part of the problem. The input is the culprit, causing me headaches. Input would have to remain 1E-11 the way it is right now. If there is no other way, i have to go with frequencies, resulting in different ranges, not sharing boundaries. Unasked for, but technically correct. – Yuki Mori Nov 23 '16 at 13:48
  • to be honest I have not the slightest idea what is the problem you are facing and I dont really understand the question. Maybe a [mcve] including actual output and output that you want might help – 463035818_is_not_an_ai Nov 23 '16 at 14:08

0 Answers0