how do i get the larger 2 out of 3 integers?

Pages: 12
naveen: use [ code] blocks and please use a proper main
llittle bobby: okay
this doesnt help me at all... how does that relate to my problem?

It does not. Directly. cire rewrote the maxofthree() code that you had with ternary operators and apparently missed your actual question.

You could do:
smallest = min( a, b, c );
sum = a + b + c - smallest;

However, if this is actually an exercise in logic, then you need to write if-clauses that reach the three branches:
1. a is the smallest
2. b is the smallest
3. c is the smallest

IF a < b
THEN we know that 'b' is not the smallest; either 'a' or 'c' is
ELSE 'b' or 'c' is the smallest
To keep it simple you could find the minimum and discard it.

1
2
3
4
5
6
if (a<b && a<c)
    ans = b+c;
else if (b<a && b<c)
   ans = a+c;
else
  ans = a+b;
Last edited on
cire rewrote the maxofthree() code that you had with ternary operators and apparently missed your actual question.

I didn't miss the question. I just don't see any point in taking it to conclusion given the lack of effort the OP has shown past the initial post.

"Your code works; make it simpler so my professor doesn't think I cheated" or "your code works but it uses two functions; make it use one function for me" doesn't really qualify as effort to me.
Topic archived. No new replies allowed.
Pages: 12