Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Aug 2007
    Location
    Kolkata,India
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cool Ternary Operator Help

    Can anyone help me write this Excel formula in C/C++
    Code:
    =IF(C3>300000;IF(C3>600000;IF(C3>900000;IF(C3>1200000;IF(C3>1800000;IF(C3>2399999;300000);210000);90000);60000);45000);0)

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Location
    Kansas City, Kansas
    Posts
    1,518
    Thanks
    0
    Thanked 2 Times in 2 Posts
    I'm not totally sure on Excel's syntax, but it could be something like this.
    Code:
    if (C3 > 300000)
    {
      if (C3 > 600000)
      {
        if (C3 > 900000)
        {
          if (C3 > 1200000)
          {
            if (C3 > 1800000)
            {
              if (C3 > 2399999)
                return 300000;
              else
                return 210000;
            }
            else
              return 90000;
        }
        else
          return 6000;
      }
      else
        return 45000;
    }
    else
      return 0;
    Edit: Oops. I just noticed that you specified ternary operator in your thread title. See if this works for you.
    Code:
    return C3 > 300000 ? (C3 > 600000 ? (C3 > 900000 ? (C3 > 1200000 ? (C3 > 1800000 ? (C3 > 2399999 ? 300000 : ) : 210000) : 90000) : 60000) : 45000) : 0;
    Last edited by Antoniohawk; 09-29-2007 at 05:07 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •