Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

i needz help (C++)

Name: Anonymous 2007-12-20 11:59

hay guyz.

Anyways, I new to programming, I need to know how to use the || operator properly.

ie.

if number is not 3 or 4. ask for another input.
could someone give me an example?
not sure at what point in a loop it goes at.
assuming it could be in a do ( cout << "plz enter valid number: " cin >> number ) while (number != 3 || 4) or something?
but that doesn't work.
It keeps telling me that my number is invalid.

Cheers,
anon.

Name: Anonymous 2007-12-20 12:49

>>5
Then use ||. It's just like in logic, but I believe it short circuit evaluates. So something like if (1 || imUsingSepples()) {} would never evaluate imUsingSepples(). Any side effects of that function (dick in your ass, &c.) will not occur.

And || is a connective, not a predicate. You can only use it on true/false values. if (number = 3 || number = 4) {}

If you want to make several comparisons against the same integer, use a switch.
[code]switch (number) {
  case 4:
  case 6:
    cout << "Good job, faggot.";
    break;
  default:
   cout << "Ur a faggot.";
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List