how do this exercise

well, the exercise is do a program that read 3 numbers and show who is the greater.

example: 4,8,1 the greater is 8.

is easy but I can't use "if" so that is my problem, beacuse i'm a begginer in c++ but I see the lesson about the conditionals , but I don't know how this problem . please do you help me whit this?
Is it that you're not allowed to use "if" for the problem, or you're just not sure how to use "if" conditions?
No, in my guide exercise are 8 exercise ok?, and down of thats exercise are the exercise about of "if" , so I understand that I can't use
I know use "if" but I want know if this problem can do without conditional "if".
I guess I would generally use an if statement for this comparison. Have you covered the ternary operator?

larger = ( a > b ? a : b );

http://www.cprogramming.com/reference/operators/ternary-operator.html
You cannot do it without a conditional. Ternary operator.
Well, I think a very long time and I can't find a solution for this problem without "if" , I believer that only solution is with "if" sure?
You need to compare values, either with if or the ternary operator.
mmm yes ok, is necessary compare values, but I want know if I can this problem whitout use "if" and "else".
As has already been said, yes. Use the ternary operator.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>

int max(int a, int b)
{
    return a < b ? b : a;
}

int main()
{
    int a = 4;
    int b = 8;
    int c = 1;

    std::cout << "The greater is " << max(a, max(b,c)) << '\n';
}
ah ok, I understand now, sorry, i'm from venezuela (we speak spanish) and I don't speak perfect english, that operator I meet with other name , I had not understood.

sorry and thank you so much :)
even without using ternary operator will do
Topic archived. No new replies allowed.