Please Write me a simple code of Logical Operator
-
Wednesday, May 18, 2011 8:10 PMHello I know how logical operators actually work, but I can't place them simply within a complete script I would be so grateful if anybody write me a very simple code but complete. For Example: If it's possible, write a code that: If (x = 1) and (y = 2), then print " Very Good Person You Are". Thank You So Much!!!
The World Needs To be Deeply Cleaned.
All Replies
-
Wednesday, May 18, 2011 8:23 PMCan you show what you have tried so far?
-
Wednesday, May 18, 2011 9:00 PM
>If (x = 1) and (y = 2)
For starters, note that in C/C++ the '=' is the
assignment operator, not the equality comparison
operator. So in actual code you would need:
if(x == 1)
e.g. - if(x == 1 && y == 2)
Examples here:
C++ Operators
http://msdn.microsoft.com/en-us/library/x04xhy0h(v=VS.100).aspx
- Wayne- Marked As Answer by Rob PanModerator Wednesday, May 25, 2011 8:35 AM
-
Thursday, May 19, 2011 4:48 AM
#include<iostream> using namespace std; int _tmain(int argc, _TCHAR* argv[]) { int M1 = 60, M2 = 70; // Assignment oper if(M1 >= 50) cout <<" Pass in Subject1"<< endl; if(M2 >= 50) cout <<" Pass in Subject2"<< endl; if( (M1>=50) && (M2 >= 50)) // Logical AND: && cout <<" Pass"<< endl; if( (M1<50) || (M2 <50)) // Logical OR: || cout <<" Fail"<<endl; return 0; }
Thanks and Regards Selvam http://www15.brinkster.com/selvamselvam/- Marked As Answer by Rob PanModerator Wednesday, May 25, 2011 8:35 AM

