dimanche 28 juin 2020

IF-nesting in c++

heyall, just going through some textbook examples for my introductory c++ course and I would really appreciate it if somebody could clarify why the following code produces an output of 51 (I would expect it to not produce any output whatsoever), many thanks!:

#include <iostream>
using namespace std;

int main()
{
  constexpr int a{9};
  constexpr int b{1};
  constexpr int c{5};

  if (a < b < c)
    if (c > b > a)
      if (a > c) cout << 91;
      else cout << 19;
    else
      if (b < c) cout << 51;
      else cout << 15;
  else 
    if (b < a < c)
      if (a < c) cout << 95;
      else cout << 59;
    else
      if (b < c) cout << 57;
      else cout << 75;

  return 0;
}

Aucun commentaire:

Enregistrer un commentaire