logical Circuit

I am getting error in If statement after (k nor i) "!&" need a ')'. But i Don't know how to fix this--

Pls help!

1
2
3
4
5
6
7
8
9
10
cout<< "\n\n (A and B) xnor((C nor A) nand(B xnor C))" <<endl;
	for( int i=0; i<2; i++){
		for (int j=0; j<2; j++){
			for( int k=0; k<2; k++){
		cout<< "A: " << i<< ", B: "<<j <<",C: " <<k<< "->";
				if((i&& j)^! (((!(k||i))!&(j!^k)))))
					'''''

}
} 
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
#include <iomanip>

inline bool AND( bool a, bool b ) { return a && b ; }
inline bool OR( bool a, bool b ) { return a || b ; }
inline bool XOR( bool a, bool b ) { return (a+b) == 1 ; }
inline bool NAND( bool a, bool b ) { return !(a&&b) ; }
inline bool NOR( bool a, bool b ) { return !OR(a,b) ; }
inline bool XNOR( bool a, bool b ) { return !XOR(a,b) ; }

int main()
{
    std::cout << "A B   AND NAND   OR NOR   XOR XNOR\n----------------------------------\n\n" ;
    for( bool a : { false, true } ) for( bool b : { false, true } )
    {
        std::cout << a << std::setw(2) << b
                  << std::setw(5) << AND(a,b)
                  << std::setw(4) << NAND(a,b)
                  << std::setw(6) << OR(a,b)
                  << std::setw(4) << NOR(a,b)
                  << std::setw(6) << XOR(a,b)
                  << std::setw(5) << XNOR(a,b) << "\n\n" ;
    }

    bool A = true, B = false, C = true ;
    std::cout << "\n\n(A and B) xnor((C nor A) nand(B xnor C))\n" ;
    std::cout << XNOR( AND(A,B), NAND( NOR(C,A), XNOR(B,C) ) ) << '\n' ;
}

http://coliru.stacked-crooked.com/a/d6d44aa8aef9b1fc
@JLBorges

I don't understand the meaning of line 14. I tried it in Visual c++ 2010 but it's giving error and I actually need 8 outputs of true false in this
T
T
T
T
F
F
F
F
> I don't understand the meaning of line 14.

See: http://www.stroustrup.com/C++11FAQ.html#for


> I tried it in Visual c++ 2010 but it's giving error

For C++98, write classical for loops :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>

inline bool AND( bool a, bool b ) { return a && b ; }
inline bool OR( bool a, bool b ) { return a || b ; }
inline bool XOR( bool a, bool b ) { return (a+b) == 1 ; }
inline bool NAND( bool a, bool b ) { return !(a&&b) ; }
inline bool NOR( bool a, bool b ) { return !OR(a,b) ; }
inline bool XNOR( bool a, bool b ) { return !XOR(a,b) ; }

int main()
{
    std::cout << std::boolalpha ;

    for( int A = 0 ; A < 2 ; ++A )
        for( int B = 0 ; B < 2 ; ++B )
            for( int C = 0 ; C < 2 ; ++C )
                 std::cout << XNOR( AND(A,B), NAND( NOR(C,A), XNOR(B,C) ) ) << '\n' ;
}
"I don't understand the meaning of line 14."

Alternative reference: http://en.cppreference.com/w/cpp/language/range-for

In old school C++ you could also use this, although an index would probably be easier to read:

1
2
for( bool a = false, aa = true; aa != a; a = a || aa, aa = !aa )
                for( bool b = false, bb = true; bb != b; b = b || bb, bb = !bb)
Thanks All. It's good now
Topic archived. No new replies allowed.