title: How do I convert if then else to an expression using ternary operators
body: <p>I would like the following function to be defined using ternary operators rather than <code>if</code>, <code>else</code> and <code>else if</code> statements.</p>
  
  <pre><code>#include &lt;iostream&gt; //Conditional Ternary Operator (if ? :else )
  using namespace std;
  int greatest(int a,int b,int c)
  {
     // what I tried
    (a&gt;b &amp;&amp; a&gt;c) ?return (a); :(b&gt;a &amp;&amp; b&gt;c) ?return (b); :return(c);
  
    // what I want
    /* if(a&gt;b &amp;&amp; a&gt;c)
    return(a);
    else if (b&gt;a &amp;&amp; b&gt;c)
      return (b);
    else
      return(c);
    */
  }
  
  
  int main()
  {
   int a,b,c;
   cout&lt;&lt;"Enter a :";
   cin&gt;&gt;a;
   cout&lt;&lt;"Enter b :";
   cin&gt;&gt;b;
   cout&lt;&lt;"Enter c:";
   cin&gt;&gt;c;
   cout&lt;&lt;greatest(a,b,c)&lt;&lt;": Is Greater";
   return 0;
  }
  </code></pre>