Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HistArr depend(int a, int b, int c, struct HistArr histarr)
{
    if (b != a)
    {
        if (c != a)
        {
            if (histarr.his[b].number == histarr.his[c].number)
            {
                histarr.his[b].result = histarr.his[b].result + histarr.his[c].result;
                return depend(a - 1, b, c, del(a, c, histarr));
            }
            else
            {
                return depend(a, b, c + 1, histarr);
            }
        }
        else
        {
            return depend(a, b + 1, b + 2, histarr);
        }
    }
    else
    {
        histarr.count = a;
        return histarr;
    }

}


What I have tried:

I tried to ?,: use these operators but unable to make it work.
Posted
Updated 28-Sep-22 1:38am
Comments
Richard MacCutchan 28-Sep-22 7:25am    
Well since your code does not contain an example of using those operators, or any explanation of the problem, we cannot make any useful suggestions.

1 solution

The ternary operator isn't a substitute for if...else, or even a shorthand for it - though under some circumstances it can be used that way.
For example, this code:
C++
if (a > b)
   c = a;
else
   c = b;
Can be shortened using a ternary operator to this:
C++
c = a > b ? a : b
Because both the if and else blocks have one job: setting the value of the same variable.
Your code doesn't do that: it does "extra" things like setting the value of histarr.count.
While it could be possible to mangle that code into a couple of nested ternary operators using a bunch of subroutines, the resulting code would be almost unreadable, and would be very hard to both debug and modify.

Just because you can do something, doesn't mean you should!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900