hi ..

please can anyone help me with this .. i need it today

i wanna to do swith with this .. can i or not?

if ( x>y )
cout<< " x is bigger ";
else
cout<< " y is bigger ";

--
and i wanna to do conditional operator with more than 2 expressions .. can i do that?
and is that write or wrong?

grade == 'A' ? "ex" : grade == 'B' ? "v.g" : grade == 'c' ? "g" : undefined letter

thanx :)

Both should work.
Personally, I prefer to use lots of parentheses to make it obvious (both to myself and to the compiler) what exactly I mean to say:

cout << (
  (grade == 'A') ? "excellent" : (
    (grade == 'B') ? "very good" : (
      (grade == 'c') ? "good" : "not so good at all" )))
  << endl;

Hope this helps.

switch( x>y ) { ... } ?

Duoas .. thanx alot .. :)

---
twomers .. i don't understand ?

please any one answer me in q1

Sure. Boolean is an ordinal type.

switch (x < y) {
  case true:
    // hmm, x < y
    break;
  case false:
    // wait, x >= y
  }

[EDIT] man, too slow again...

No prob DREAMER546 :-)

thanx aloot really .. because i read in the book the swith just take a constant integral expression i were think when we put < is wrong ..

Member Avatar for iamthwee

All this: "I wanna do this by using that is nonsense."

As long as you use something that you understand it doesn't matter honey!

yeah i know that we show use what we understand .. but there's questions that request to solve it by a define way .. so that i'm asking for another way ..

Yoinks, iamthwee, at least she is asking to learn...

This is an expression: x > y . It evaluates to an integral (aka ordinal) value (specifically, a bool), which is what the switch statement takes. So when you say switch (something) { as long as something evaluates to an integral expression then the switch will work just fine.

Nobody uses switch for boolean expressions because it is faster and easier to read just to use an if. The if, btw, also takes an integral expression. If zero, it is understood as false. If non-zero, it is understood as true.

Hope this helps.

Duoas .. really thanks alooot :) .. that's help me alot

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.