If else

How i make the code to read all the conditions before making decision

if ((S1 == S2) || (S1 == S3) || (S2 == S3))
{
cout << "Segitiga sama kaki";
}
else if ((S1 == S3) && (S1 == S2) && (S2 == S3))
{
cout << "segitiga Sama Sisi";
}
else
{
cout << "segitiga sembarang";
}
you don't need to do this normally, and it is bloated and annoying to do it. can you explain exactly what you want to do (the above code does not need this level of messy code at all).
you can do it with a bitset or integer or other similar 'state' type variable, even an enum will work.
enum{empty, state1, state2, ....}
state &= (s1==s2)*state1;
state &= (s1==s3)*state2;
...
and then some logic after all that:
switch (state)
... //use fall through and breaks to group and organize the states
Last edited on
Operator overloading of those operators forces it to not short circuit.

(But, to be clear, this is not really considered a good thing. Probably counts as a 'code smell' to be overloading those operators. I've personally never done it.)
Last edited on
How i make the code to read all the conditions before making decision

Given that you appear to be making decisions about triangles - scalene, isosceles, equilateral - you simply can't do it with a single test.

And that's without deciding whether the 3 sides form a triangle in the first place.

Tidak bagus :(
Topic archived. No new replies allowed.