I have a task in which I need to output "YES" or "NO", without using the branch operators if, switch ....

Here is the condition:

Write a program that determines whether a given point falls in the shaded area. Boundary points enter the area.

-------- | -5 ////// 1 | ----------- | 7 /////// 13 | --------- ->

Input Format

A real number x is entered, which does not exceed 105 in absolute value and is set with an accuracy of two decimal places.

Output format

Print “YES” if the coordinates of the point fall into this area, and “NO” otherwise.

Examples

Input | 10.00 | YES

Output | 0.00 | YES

I figured out how to output 1 or 0. But I don’t know how “YES” or “NO”.

PS You can not use arrays and functions

  • You specify what can be used and what can not. The fact is that the string is an array of char . "use strings" and "don't use arrays" are mutually exclusive paragraphs - yrHeTaTeJlb
  • @ gil9red If people do not know neither the conditions, nor the arrays, nor the functions, then how should they decide? - Skufler
  • This is basic knowledge :) the first pages of any programming textbook :) - gil9red

3 answers 3

Here is a variant from @KoVadim from which the array declaration is dropped:

 #include <iostream> using namespace std; void show(int i) { cout << ("NO\0YES\0" + i*3); } int main() { // your code goes here show(0); cout << "\n"; show(1); cout << "\n"; return 0; } 

But as I wrote in the comment to the question, the string is an array of char . Cannot use strings and not use arrays.

    Here is a small example. Understand?

     #include <iostream> using namespace std; void show(int i) { const char a[] = "NO\0YES\0"; cout << (a + i*3); } int main() { // your code goes here show(0); cout << "\n"; show(1); cout << "\n"; return 0; } 
    • Thank you very much, of course, but our teacher does not allow the use of methods and arrays, because in the group I only know them. That's what the problem is - Skufler
    • 2
      @MatvieiSkufin, does he allow strings to be used? Then I have news for him ... - PinkTux
    • No, we didn’t pass them either - Skufler
    • @MatvieiSkufin, how didn’t they? And yes / no how do you spell out the Hindu code? - PinkTux
    • @PinkTux Before that, all tasks needed to output 0 or 1 - Skufler
     const char *answers[] = { "NO", "YES" }; bool rc = isPointInRegion(/* ... */); std::cout << answers[ (size_t)rc ]; 
    • Arrays cannot be used :( - Skufler
    • @MatvieiSkufin, then the KoVadim option will suit you (assuming that your teacher does not know that the lines are also arrays) - PinkTux
    • I think he is not so stupid. - Skufler
    • @MatvieiSkufin, it means that you do not understand something. Show your code to display at least some data that does not use strings. - PinkTux
    • I thought by strings, you mean string. - Skufler