a56444c a56444c - 1 year ago 78
C++ Question

Compact multi-conditional if statement

I have the simplest question ever. I was practising with the

statement and wondered if I could print out different messages under different conditions, but I wanted to keep it simple. If the 1st condition is true, the 1st line of
will print; and if the 2nd condition is true, the 2nd line of
will print; and so on. Code follows;

int x; cin >> x;
int y; cin >> y;

cout << x << " is smaller than " << y << endl;
cout << x << " is bigger than " << y << endl;
cout << x << " is equal to " << y << endl;

Apparently there is something missing, some kind of
s between the
s. Is it possible to keep this code as compact as it is and make it function properly?

Answer Source

What to you mean by simple? If compact, then this is correct (but not the most readable) . .


. . or go crazy and make == the default case to save a char

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download