Table of Contents
Back Button
Back to Chapter
C++ Setting Up
C++ Introduction
No items found.
C++ Basics
No items found.
C++ Control Statements
No items found.
C++ Logical Operators
No items found.
C++ Procedural Programming
No items found.
C++ Structural Programming
No items found.
C++ Implementation of OOPS
No items found.
C++ Arrays and Vectors
No items found.
C++ Error Handling
No items found.
C++ File Handling
No items found.


Suppose you wish to play football with your friend on Sunday, you call him and ask him if he's available. He says he will play football only if "it is sunny and the ball is of size 5".

If we were to write this in C++ based on the knowledge we have

if(isSunny == true) { if(size==5) { cout<<"your friend will play"; } }

But C++ provides us with an easier method that is much simpler to understand and makes more sense. AND allows us to compare two expressions and give true value.

Truth value sometimes called a logical value, is a value indicating the relation of a proposition to truth. Basically truth value refers to a value of a proposition being true or false.

For a computer true means 1 and false means 0 therefore if value of AND is true then for computer it is 1, and 0 for false.

From above truth table we understand that AND give value 1 only if all expression are true. Let us do the same for 3 expression

Now let us write a program to provide discount of 20% to members of the gym above the age of 30.

#include using namespace std; main() { int age; bool isMem; cout<<"Are u a member:\n1.yes\\n"; cin>>isMem; cout<<"enter your age:\n"; cin>>age; if((isMem ==1&&(age>=30)) { cout<<"congratz!!! you get a discount of 20%\n"; } else { cout<<"no discount\n"; } }
Output: Are u a member: 1.yes 1 enter your age: 40 congratz!!! you get a discount of 20%
Ask queries
Contact Us on Whatsapp
Hi, How Can We Help You?