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

Boolean Algebra; Help!

Name: Anonymous 2008-03-06 16:51

#include <iostream>

using namespace std;

int main()

{
   
    float number;
   number = 9;
    if (number == 2 || 3)
    {cout<<"\n\nRight!";}
    else{cout<<"Wrong";}
    cin.get();
   
}


This script (in my understnding) should display "Wrong", it actually displays "Right"

Help?

Name: Anonymous 2008-03-06 16:54

I think you have to fix your coding style for the code to work.

Name: Anonymous 2008-03-06 16:55

Explain?

Name: Anonymous 2008-03-06 16:57

number == 2 | 3

Name: Anonymous 2008-03-06 16:57

For starters, use code tags.

Name: Anonymous 2008-03-06 17:00

>>3
int main()

{

What the fuck, mang?  Why the blank line?

Name: Anonymous 2008-03-06 17:00

>>5

Code tags?

Name: Anonymous 2008-03-06 17:02

>>6

Why not?

Name: Anonymous 2008-03-06 17:05

>>8
It's a waste of a vertical line, it also looks like shit.  If anything, put the return type on a line of its own and make sure the function's name starts on the first column so functions can easily be found with grep ^function.

Name: Anonymous 2008-03-06 17:06

>>9
It's a waste of a vertical line, it also looks like shit.
That's why we use FIOC in BBCode.

Name: Anonymous 2008-03-06 17:06

Employing scalable agile SAGE methodology for a multi-tier amplification of the TCO responsibility of your business product management.

Name: Helpful Sage 2008-03-06 17:20

You are testing if number == 2, then if 3, so it will always be true as 3 is true.
Also, READ SICP

Name: Anonymous 2008-03-06 17:33

Since nobody else has actually included what the right code is, here you go...

if (number == 2 || number == 3)

The operators == || && all take two numbers and produce either 0 or 1.

== produces 1 if the two numbers are equal and 0 otherwise.
|| produces 0 if both numbers are 0 and 1 otherwise.
&& produces 1 if both numbers are 1 and 0 otherwise.

Hence, (number == 2 || 3) can be read as (number == 2) || 3, regardless of what the left side of || is, the right side is 3, which is not 0, and so the || returns 1 (true).

Name: Anonymous 2008-03-06 17:52

>>13

Thanks, appreciate it.

It's people like you that mean the more cerebral boards aren't degraded into /b/ replicates.

Name: Anonymous 2008-03-06 18:14

>>1,12-14
Same person and we have been trolled constantly.

Name: Anonymous 2008-03-06 18:21

>>15

Back to /b/

Name: Anonymous 2008-03-06 18:45

>>16
back to /b/, please.

Name: Anonymous 2008-03-06 18:55

>>13
regardless of what the left side of || is, the right side is 3, which is not 0, and
You mean "regardless of what the *right* side is, if the left side is true, then right side is not evaluated".
faggot.

Name: Anonymous 2008-03-06 19:27

>>18
While what you're saying is true, it doesn't have anything to do with what >>13 was trying to say.

Name: Anonymous 2008-03-06 19:33

>>13
&& produces 1 if both numbers are 1 and 0 otherwise.
No, it produces 1 if both numbers are non-zero.

Name: Anonymous 2008-03-06 20:46

>>20
Not just numbers, pointers are allowed too.

Name: Anonymous 2008-03-06 21:59

what?
just do:

int main ()
{
   int num = 9;
   if (num == 2 || num == 3)
      printf ("Right!\n");
   else
      printf ("Wrong!\n");
  
   return 0;
}


And it's not a script you stupid faggot.

Name: Anonymous 2008-03-06 22:34

>>21
Pointers are numbers too, faggot.

Name: Anonymous 2008-03-06 22:55

>>23
Read ``ISO/IEC 9899:1990''

Name: Anonymous 2008-03-07 0:25

>>23
characters are numbers too, faggot.

Name: Anonymous 2008-03-07 3:04

>>25
you are a number too, faggot.

Name: Anonymous 2008-03-07 3:48

Name: Anonymous 2008-03-07 5:37

>>26
your are a #2 faggot

Name: Anonymous 2008-03-07 5:46

>>28
You are a ⑨, Cirno.

Name: Anonymous 2008-03-07 5:47

ZA WARUDO ➒

Name: Anonymous 2009-03-06 5:54


Allocation than Pascal anyhow   And I had   been hired to   write a FORTRAN   compiler for this   I think the   DEVELOPER OF BBCODE   USED AN IDE   not just an   excuse not to   hate it is   unscientific and ultimately   ungrammatical Well not   as cool as   I wanted but.

Name: Anonymous 2013-09-02 13:06

Name: Anonymous 2013-09-10 1:54


                        ██████████████████████                                                                           
      ██████████████████                      ████            ██████████████    ████    ██    ██  ██████    ████    ██    ██
    ██                      ██                    ████  ████████████████████  ██    ██  ██    ██  ██      ██    ██  ██  ██
    ██                  ████            ██            ████    ██████████████  ██        ████████  ████    ██        ████ 
      ██████████████████          ██████                ██    ██████████████  ██    ██  ██    ██  ██      ██    ██  ██  ██
                    ██        ████    ██                ██    ██████████████    ████    ██    ██  ██████    ████    ██    ██
                    ██████████        ██                ██    ██████████████                                             
                      ██          ████  ██              ██    ██████████████  ██████████  ██    ██  ██████  ██      ██   
                        ██████████      ██              ██    ██████████████      ██      ██    ██  ██      ████  ████   
                          ██        ████  ██            ██    ██████████████      ██      ████████  ████    ██  ██  ██   
                            ████████      ██            ██    ██████████████      ██      ██    ██  ██      ██      ██   
                            ██        ████              ██    ██████████████      ██      ██    ██  ██████  ██      ██   
                              ████████            ████████    ██████████████                                             
                                      ████████████      ████████████████████                                             
                                                              ██████████████

Name: Anonymous 2013-09-12 8:27

{-# OPTIONS_GHC -F -pgmF she #-}
{-# LANGUAGE LambdaCase #-}

import Control.Applicative

main :: IO ()
main =
  let number = 9 in
   putStrLn . \case; True -> "Right!"; False -> "Wrong!"; . (| (==2) || (==3) |) $ number

Name: Anonymous 2013-09-12 14:40

Applicative
I raged!!!

9/10

Name: Anonymous 2013-09-12 15:16

[bold]RAGE[/bold]

Name: Anonymous 2013-09-12 15:45

>>34
optimized:
main :: IO ()
main = putStrLn "Wrong!"

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