0

I need to write a c++ Projekt and the conditions are, i can only use the < to compare 2 variables. I cant use <=, >=, >, ==, !=. But now i need to compare 2 variables. How can i compare them, if they are the same without using ==.

Example:

 if {
A == B; // can´t use this but need to scan if they are the same
}

i have 0 idea how to do that so i hope any of you can help me. I tried to do it like

A < B && B < A but i think i cant get to the solution.

Hikko
  • 1
  • 1
    Pop quiz: if the first variable is not less than the 2nd variable, and the 2nd variable is not less than the first one, then what conclusions can you draw from this? – Sam Varshavchik Dec 07 '22 at 13:48
  • 1
    @SamVarshavchik and OP, note, it's only valid if it's fully ordered. Some types are partially ordered and thus `!(A < B) && !(B < A) && !(A == B)` is still possible. E.g. nan, but there are other useful cases as well. – lorro Dec 07 '22 at 13:50
  • 1
    What is the type(s) of `A` and `B`? If they are `float` or `double`, the answer is different than if they are `char` or `int`. If you don't know, then the answer is "it depends". – Eljay Dec 07 '22 at 13:54
  • `A < B && B < A ` can't possibly be true, since `A` and `B` can't both be less than the other. (Hint: "X is greater than or equal to Y" is equivalent to `X is not less than Y", and you *are* allowed to use negation.) – molbdnilo Dec 07 '22 at 14:21
  • @molbdnilo in principle it can be `true` for some weird type, it would have rather useless `<` but its not impossible – 463035818_is_not_an_ai Dec 07 '22 at 14:23
  • 1
    @463035818_is_not_a_number And in principle, I could have been a famous actor in Hollywood. – molbdnilo Dec 07 '22 at 14:25

0 Answers0