SlideShare a Scribd company logo
Diagram
Get Fromoperator
The bitwise shift operators are the right-shift operator (>>), which
moves the bits of shift_expression to the righ
the left-shift operator (<<), which moves the bits of shift_expression to the left.
C++if,if...else and Nested if...else
In this article, you will learn to create decision making statements in a C++ program
using different forms of if. else statement.
C++if Statement
if (testExpression)
{
// statements
}
The if statement evaluates the test
expression
inside parenthesis.
If test expression is evaluated to true,
statements inside the body of if is
executed.
If test expression is evaluated to false,
statements
inside the body of if is skipped.
How if statementworks?
Flowchart of ifStatement
Example 1:C++if Statement
// Program to print positive number entered by the user
// If user enters negative number, it is skipped #include
<iostream>
using namespace std; int main()
{
int number;
cout << "Enter an integer: ";
cin >> number; // checks if the number is positive if ( number
> 0)
{
cout << "You entered a positive integer: " << number << endl;
}
cout << "This statement is always executed."; return 0;
}
Output
Output 1
Enter an
integer: 5
You entered
a positive
number: 5
This
statement is
always
executed.
C++if...else
• The if else executes the codes
inside the body of if statement if
the test expression is true and
skips the codes inside the body
of else.
• If the test expression is false, it
executes the codes inside the
body of else statement and skips
the codes inside the body of if.
How if...elsestatementworks?
Flowchart of if...else
C++Nested if...else
#include <iostream>
using namespace std;
int main()
{
float n1, n2, n3;
cout << "Enter three numbers: ";
cin >> n1 >> n2 >> n3;
if (n1 >= n2)
{
if (n1 >= n3)
cout << "Largest number: " << n1;
else
cout << "Largest number: " << n3;
}
else
{
if (n2 >= n3)
cout << "Largest number: " << n2;
else
cout << "Largest number: " << n3;
return 0;
}
Syntax of Ladder elseif
if (testExpression1)
{
// statements to be executed if testExpression1 is true
}
else if(testExpression2)
{
// statements to be executed if testExpression1 is false and testExpression2 is true
}
else if (testExpression 3)
{
// statements to be executed if testExpression1 and testExpression2 is false and
testExpression3 is true
} . . else
{
// statements to be executed if all test expressions are false
}
Switch
Statement

More Related Content

What's hot

Learning C programming - from lynxbee.com
Learning C programming - from lynxbee.comLearning C programming - from lynxbee.com
Learning C programming - from lynxbee.com
Green Ecosystem
 
Mycasestudy
MycasestudyMycasestudy
Mycasestudy
Emmanuel college
 
Assignment12
Assignment12Assignment12
Assignment12
Sunita Milind Dol
 
04 control structures 1
04 control structures 104 control structures 1
04 control structures 1Jomel Penalba
 
Control statements
Control statementsControl statements
Control statements
Kanwalpreet Kaur
 
If else statement in c++
If else statement in c++If else statement in c++
If else statement in c++
Bishal Sharma
 
Bakery Algorithm
Bakery Algorithm Bakery Algorithm
Bakery Algorithm
thededar
 
Infix to postfix
Infix to postfixInfix to postfix
Infix to postfix
Saeed Farooqi
 
Csc1100 lecture05 ch05
Csc1100 lecture05 ch05Csc1100 lecture05 ch05
Csc1100 lecture05 ch05IIUM
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
Sokngim Sa
 
Getting started in c++
Getting started in c++Getting started in c++
Getting started in c++
Neeru Mittal
 
Csc1100 lecture06 ch06_pt1
Csc1100 lecture06 ch06_pt1Csc1100 lecture06 ch06_pt1
Csc1100 lecture06 ch06_pt1IIUM
 
Csc1100 lecture02 ch02-datatype_declaration
Csc1100 lecture02 ch02-datatype_declarationCsc1100 lecture02 ch02-datatype_declaration
Csc1100 lecture02 ch02-datatype_declaration
IIUM
 
Csc1100 lecture06 ch06_pt2
Csc1100 lecture06 ch06_pt2Csc1100 lecture06 ch06_pt2
Csc1100 lecture06 ch06_pt2IIUM
 
Repetition Structure
Repetition StructureRepetition Structure
Repetition Structure
PRN USM
 
C++ decision making
C++ decision makingC++ decision making
C++ decision making
Zohaib Ahmed
 
Assignment6
Assignment6Assignment6
Assignment6
Sunita Milind Dol
 

What's hot (20)

Learning C programming - from lynxbee.com
Learning C programming - from lynxbee.comLearning C programming - from lynxbee.com
Learning C programming - from lynxbee.com
 
Mycasestudy
MycasestudyMycasestudy
Mycasestudy
 
Assignment12
Assignment12Assignment12
Assignment12
 
04 control structures 1
04 control structures 104 control structures 1
04 control structures 1
 
Control statements
Control statementsControl statements
Control statements
 
If else statement in c++
If else statement in c++If else statement in c++
If else statement in c++
 
Bakery Algorithm
Bakery Algorithm Bakery Algorithm
Bakery Algorithm
 
Infix to postfix
Infix to postfixInfix to postfix
Infix to postfix
 
Csc1100 lecture05 ch05
Csc1100 lecture05 ch05Csc1100 lecture05 ch05
Csc1100 lecture05 ch05
 
Kelompok 8 Pbw
Kelompok 8 PbwKelompok 8 Pbw
Kelompok 8 Pbw
 
Kelompok 8 Pbw
Kelompok 8 PbwKelompok 8 Pbw
Kelompok 8 Pbw
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
 
Getting started in c++
Getting started in c++Getting started in c++
Getting started in c++
 
Csc1100 lecture06 ch06_pt1
Csc1100 lecture06 ch06_pt1Csc1100 lecture06 ch06_pt1
Csc1100 lecture06 ch06_pt1
 
Csc1100 lecture02 ch02-datatype_declaration
Csc1100 lecture02 ch02-datatype_declarationCsc1100 lecture02 ch02-datatype_declaration
Csc1100 lecture02 ch02-datatype_declaration
 
Csc1100 lecture06 ch06_pt2
Csc1100 lecture06 ch06_pt2Csc1100 lecture06 ch06_pt2
Csc1100 lecture06 ch06_pt2
 
Repetition Structure
Repetition StructureRepetition Structure
Repetition Structure
 
C++ decision making
C++ decision makingC++ decision making
C++ decision making
 
Assignment6
Assignment6Assignment6
Assignment6
 
C++ control loops
C++ control loopsC++ control loops
C++ control loops
 

Similar to Cin and cout

Chap 4 c++
Chap 4 c++Chap 4 c++
Chap 4 c++
Chap 4 c++Chap 4 c++
C Control Statements.docx
C Control Statements.docxC Control Statements.docx
C Control Statements.docx
JavvajiVenkat
 
Programming Fundamentals Decisions
Programming Fundamentals  Decisions Programming Fundamentals  Decisions
Programming Fundamentals Decisions
imtiazalijoono
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statements
Saad Sheikh
 
Programming fundamental 02
Programming fundamental 02Programming fundamental 02
Programming fundamental 02
Suhail Akraam
 
Basics of Control Statement in C Languages
Basics of Control Statement in C LanguagesBasics of Control Statement in C Languages
Basics of Control Statement in C Languages
Chandrakant Divate
 
C decision making and looping.
C decision making and looping.C decision making and looping.
C decision making and looping.
Haard Shah
 
Simple if else statement,nesting of if else statement &amp; else if ladder
Simple if else statement,nesting of if else statement &amp; else if ladderSimple if else statement,nesting of if else statement &amp; else if ladder
Simple if else statement,nesting of if else statement &amp; else if ladder
Moni Adhikary
 
Control structure of c
Control structure of cControl structure of c
Control structure of c
Komal Kotak
 
Conditional and control statement
Conditional and control statementConditional and control statement
Conditional and control statement
narmadhakin
 
C operators
C operatorsC operators
C operators
srmohan06
 
FP 201 Unit 3
FP 201 Unit 3 FP 201 Unit 3
FP 201 Unit 3 rohassanie
 
Decision making using if statement
Decision making using if statementDecision making using if statement
Decision making using if statement
CHANDAN KUMAR
 
conditionalanddvfvdfvdvdcontrolstatement-171023101126.pdf
conditionalanddvfvdfvdvdcontrolstatement-171023101126.pdfconditionalanddvfvdfvdvdcontrolstatement-171023101126.pdf
conditionalanddvfvdfvdvdcontrolstatement-171023101126.pdf
sdvdsvsdvsvds
 
C programming Control Structure.pptx
C programming Control Structure.pptxC programming Control Structure.pptx
C programming Control Structure.pptx
DEEPAK948083
 
L05if
L05ifL05if
Analysis of Microsoft Code Contracts
Analysis of Microsoft Code ContractsAnalysis of Microsoft Code Contracts
Analysis of Microsoft Code Contracts
PVS-Studio
 
CONTROLSTRUCTURES.ppt
CONTROLSTRUCTURES.pptCONTROLSTRUCTURES.ppt
CONTROLSTRUCTURES.ppt
Sanjjaayyy
 
Dti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionDti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionalish sha
 

Similar to Cin and cout (20)

Chap 4 c++
Chap 4 c++Chap 4 c++
Chap 4 c++
 
Chap 4 c++
Chap 4 c++Chap 4 c++
Chap 4 c++
 
C Control Statements.docx
C Control Statements.docxC Control Statements.docx
C Control Statements.docx
 
Programming Fundamentals Decisions
Programming Fundamentals  Decisions Programming Fundamentals  Decisions
Programming Fundamentals Decisions
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statements
 
Programming fundamental 02
Programming fundamental 02Programming fundamental 02
Programming fundamental 02
 
Basics of Control Statement in C Languages
Basics of Control Statement in C LanguagesBasics of Control Statement in C Languages
Basics of Control Statement in C Languages
 
C decision making and looping.
C decision making and looping.C decision making and looping.
C decision making and looping.
 
Simple if else statement,nesting of if else statement &amp; else if ladder
Simple if else statement,nesting of if else statement &amp; else if ladderSimple if else statement,nesting of if else statement &amp; else if ladder
Simple if else statement,nesting of if else statement &amp; else if ladder
 
Control structure of c
Control structure of cControl structure of c
Control structure of c
 
Conditional and control statement
Conditional and control statementConditional and control statement
Conditional and control statement
 
C operators
C operatorsC operators
C operators
 
FP 201 Unit 3
FP 201 Unit 3 FP 201 Unit 3
FP 201 Unit 3
 
Decision making using if statement
Decision making using if statementDecision making using if statement
Decision making using if statement
 
conditionalanddvfvdfvdvdcontrolstatement-171023101126.pdf
conditionalanddvfvdfvdvdcontrolstatement-171023101126.pdfconditionalanddvfvdfvdvdcontrolstatement-171023101126.pdf
conditionalanddvfvdfvdvdcontrolstatement-171023101126.pdf
 
C programming Control Structure.pptx
C programming Control Structure.pptxC programming Control Structure.pptx
C programming Control Structure.pptx
 
L05if
L05ifL05if
L05if
 
Analysis of Microsoft Code Contracts
Analysis of Microsoft Code ContractsAnalysis of Microsoft Code Contracts
Analysis of Microsoft Code Contracts
 
CONTROLSTRUCTURES.ppt
CONTROLSTRUCTURES.pptCONTROLSTRUCTURES.ppt
CONTROLSTRUCTURES.ppt
 
Dti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionDti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selection
 

More from Lovely Professional University

Constructors and destructors in C++ part 2
Constructors and destructors in C++ part 2Constructors and destructors in C++ part 2
Constructors and destructors in C++ part 2
Lovely Professional University
 
Constructor and destructor in C++
Constructor and destructor in C++Constructor and destructor in C++
Constructor and destructor in C++
Lovely Professional University
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
Lovely Professional University
 
Virtual Function
Virtual FunctionVirtual Function
Major project synopsis format
Major project synopsis formatMajor project synopsis format
Major project synopsis format
Lovely Professional University
 
Docslide.net soyabean milk-project-class-12
Docslide.net soyabean milk-project-class-12Docslide.net soyabean milk-project-class-12
Docslide.net soyabean milk-project-class-12
Lovely Professional University
 
Physics first page
Physics first pagePhysics first page
Physics first page
Lovely Professional University
 
Uses of transformer
Uses of transformerUses of transformer
Uses of transformer
Lovely Professional University
 
Theory and working
Theory and workingTheory and working
Theory and working
Lovely Professional University
 
Main page vishnu
Main page vishnuMain page vishnu
Main page v physics
Main page v physicsMain page v physics
Main page v physics
Lovely Professional University
 
Main page saurabh
Main page  saurabhMain page  saurabh
Introduction
IntroductionIntroduction
Efficiency and energy losses
Efficiency and energy lossesEfficiency and energy losses
Efficiency and energy losses
Lovely Professional University
 
Contents
ContentsContents
Certificate
CertificateCertificate
Bibliography
BibliographyBibliography
Apparatus
ApparatusApparatus
Acknowledgement
AcknowledgementAcknowledgement
Principle construction
Principle constructionPrinciple construction
Principle construction
Lovely Professional University
 

More from Lovely Professional University (20)

Constructors and destructors in C++ part 2
Constructors and destructors in C++ part 2Constructors and destructors in C++ part 2
Constructors and destructors in C++ part 2
 
Constructor and destructor in C++
Constructor and destructor in C++Constructor and destructor in C++
Constructor and destructor in C++
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
Virtual Function
Virtual FunctionVirtual Function
Virtual Function
 
Major project synopsis format
Major project synopsis formatMajor project synopsis format
Major project synopsis format
 
Docslide.net soyabean milk-project-class-12
Docslide.net soyabean milk-project-class-12Docslide.net soyabean milk-project-class-12
Docslide.net soyabean milk-project-class-12
 
Physics first page
Physics first pagePhysics first page
Physics first page
 
Uses of transformer
Uses of transformerUses of transformer
Uses of transformer
 
Theory and working
Theory and workingTheory and working
Theory and working
 
Main page vishnu
Main page vishnuMain page vishnu
Main page vishnu
 
Main page v physics
Main page v physicsMain page v physics
Main page v physics
 
Main page saurabh
Main page  saurabhMain page  saurabh
Main page saurabh
 
Introduction
IntroductionIntroduction
Introduction
 
Efficiency and energy losses
Efficiency and energy lossesEfficiency and energy losses
Efficiency and energy losses
 
Contents
ContentsContents
Contents
 
Certificate
CertificateCertificate
Certificate
 
Bibliography
BibliographyBibliography
Bibliography
 
Apparatus
ApparatusApparatus
Apparatus
 
Acknowledgement
AcknowledgementAcknowledgement
Acknowledgement
 
Principle construction
Principle constructionPrinciple construction
Principle construction
 

Recently uploaded

Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
GeoBlogs
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
Excellence Foundation for South Sudan
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
PedroFerreira53928
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
Nguyen Thanh Tu Collection
 

Recently uploaded (20)

Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
 

Cin and cout

  • 1.
  • 2. Diagram Get Fromoperator The bitwise shift operators are the right-shift operator (>>), which moves the bits of shift_expression to the righ
  • 3.
  • 4. the left-shift operator (<<), which moves the bits of shift_expression to the left.
  • 5. C++if,if...else and Nested if...else In this article, you will learn to create decision making statements in a C++ program using different forms of if. else statement.
  • 6. C++if Statement if (testExpression) { // statements } The if statement evaluates the test expression inside parenthesis. If test expression is evaluated to true, statements inside the body of if is executed. If test expression is evaluated to false, statements inside the body of if is skipped.
  • 9. Example 1:C++if Statement // Program to print positive number entered by the user // If user enters negative number, it is skipped #include <iostream> using namespace std; int main() { int number; cout << "Enter an integer: "; cin >> number; // checks if the number is positive if ( number > 0) { cout << "You entered a positive integer: " << number << endl; } cout << "This statement is always executed."; return 0; }
  • 10. Output Output 1 Enter an integer: 5 You entered a positive number: 5 This statement is always executed.
  • 11. C++if...else • The if else executes the codes inside the body of if statement if the test expression is true and skips the codes inside the body of else. • If the test expression is false, it executes the codes inside the body of else statement and skips the codes inside the body of if.
  • 14. C++Nested if...else #include <iostream> using namespace std; int main() { float n1, n2, n3; cout << "Enter three numbers: "; cin >> n1 >> n2 >> n3; if (n1 >= n2) { if (n1 >= n3) cout << "Largest number: " << n1; else cout << "Largest number: " << n3; } else { if (n2 >= n3) cout << "Largest number: " << n2; else cout << "Largest number: " << n3; return 0; }
  • 15. Syntax of Ladder elseif if (testExpression1) { // statements to be executed if testExpression1 is true } else if(testExpression2) { // statements to be executed if testExpression1 is false and testExpression2 is true } else if (testExpression 3) { // statements to be executed if testExpression1 and testExpression2 is false and testExpression3 is true } . . else { // statements to be executed if all test expressions are false }