...

View Full Version : Ternary Operator Help



s_pradeep
09-28-2007, 09:49 AM
Can anyone help me write this Excel formula in C/C++

=IF(C3>300000;IF(C3>600000;IF(C3>900000;IF(C3>1200000;IF(C3>1800000;IF(C3>2399999;300000);210000);90000);60000);45000);0)

Antoniohawk
09-29-2007, 03:55 AM
I'm not totally sure on Excel's syntax, but it could be something like this.

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;

Oops. I just noticed that you specified ternary operator in your thread title. See if this works for you.

return C3 > 300000 ? (C3 > 600000 ? (C3 > 900000 ? (C3 > 1200000 ? (C3 > 1800000 ? (C3 > 2399999 ? 300000 : ) : 210000) : 90000) : 60000) : 45000) : 0;



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum