SlideShare a Scribd company logo
1 of 10
Switch Case Statement
Johnny Jean N. Tigas
Zamboanga City High School
- A sequence of statements use
to verify equivalent values for
each alternative.
Syntax:
switch (expression)
{
case constant_expression1:
sequence_of_statements;
break;
case constant_expression2:
sequence_of_statements;
break;
case constant_expression3:
sequence_of_statements;
break;
…
default:
sequence_of_statements;
}
In response to this statement:
a. It takes in the value of the expression.
b. Then it will compare to the value of constant_expression1,if
it is satisfied, then the statements belonging to
constant_expression1 will be executed.
c. If constant expression1 is not satisfied, it will continue on
comparing all the constant_expressions until one is satisfied.
d. If none is satisfied, the statement(s) under default will be
executed.
Sample Problem:
A problem that lets you choose which
data to input, that is ,either your first
name, last name or middle name.
#include<iostream.h>
using namespace std;
int main ()
{ char name[10]
int opt;
cout<<“Selection…”
<<“n[1] Firstname”
<<“n[2] Lastname”
<<“n[3] Middlename”
<<“nYour choice:”;
cin>>opt;
switch(opt)
{
case 1:
cout<<“nEnter Firstname:”;
break;
case 2:
cout<<“nEnter Lastname:”;
break;
case 3:
cout<<“nEnter Middlename:”;
break;
default:
cout<<“nNone of the above.”;
}
cin>>name;
cout<<“nnHello”<<name<<endl;
return 0;
}
Possible Output:
Selection...
[1] Firstname
[2] Lastname
[3] Middlename
Your choice: 2
Enter Lastname: Tigas
Hello Tigas
Please press any key to continue
Assignment:
Consider the problem with the secret number, if
there are more than one secret number, you can
use the switch to evaluate if the user have guessed
one of the secret number. Assuming there are three
(3) secret numbers, that is: 143,431 and 314;make a
program to guess the 3 secret numbers.
THANKS!

More Related Content

Similar to Switch Case Statement in C++ Programming Language

If statements in c programming
If statements in c programmingIf statements in c programming
If statements in c programmingArchana Gopinath
 
Selection statements
Selection statementsSelection statements
Selection statementsHarsh Dabas
 
Decision Controls in C++ Programming Lecture
Decision Controls in C++ Programming LectureDecision Controls in C++ Programming Lecture
Decision Controls in C++ Programming LectureTishaFayeMendoza
 
Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)heoff
 
Hello!Can someone help me to answer Task4 and Task7Complete T.pdf
Hello!Can someone help me to answer Task4 and Task7Complete T.pdfHello!Can someone help me to answer Task4 and Task7Complete T.pdf
Hello!Can someone help me to answer Task4 and Task7Complete T.pdfforwardcom41
 
lecture 6 bca 1 year-1.pptx
lecture 6 bca 1 year-1.pptxlecture 6 bca 1 year-1.pptx
lecture 6 bca 1 year-1.pptxclassall
 
C statements
C statementsC statements
C statementsAhsann111
 
Absolute Java 5e Savitch Test Bank
Absolute Java 5e Savitch Test BankAbsolute Java 5e Savitch Test Bank
Absolute Java 5e Savitch Test BankLauriewest24
 
basic of desicion control statement in python
basic of  desicion control statement in pythonbasic of  desicion control statement in python
basic of desicion control statement in pythonnitamhaske
 
Decision Making and Branching in C
Decision Making and Branching  in CDecision Making and Branching  in C
Decision Making and Branching in CRAJ KUMAR
 
Flow of control C ++ By TANUJ
Flow of control C ++ By TANUJFlow of control C ++ By TANUJ
Flow of control C ++ By TANUJTANUJ ⠀
 
Conditional statement in c
Conditional statement in cConditional statement in c
Conditional statement in cMuthuganesh S
 
Selection Statements in C Programming
Selection Statements in C ProgrammingSelection Statements in C Programming
Selection Statements in C ProgrammingKamal Acharya
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statementsSaad Sheikh
 
Lecture 3 Conditionals, expressions and Variables
Lecture 3   Conditionals, expressions and VariablesLecture 3   Conditionals, expressions and Variables
Lecture 3 Conditionals, expressions and VariablesSyed Afaq Shah MACS CP
 

Similar to Switch Case Statement in C++ Programming Language (20)

If statements in c programming
If statements in c programmingIf statements in c programming
If statements in c programming
 
Selection statements
Selection statementsSelection statements
Selection statements
 
Decision Controls in C++ Programming Lecture
Decision Controls in C++ Programming LectureDecision Controls in C++ Programming Lecture
Decision Controls in C++ Programming Lecture
 
Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)
 
Hello!Can someone help me to answer Task4 and Task7Complete T.pdf
Hello!Can someone help me to answer Task4 and Task7Complete T.pdfHello!Can someone help me to answer Task4 and Task7Complete T.pdf
Hello!Can someone help me to answer Task4 and Task7Complete T.pdf
 
Decision Making.pptx
Decision Making.pptxDecision Making.pptx
Decision Making.pptx
 
CH-4 (1).pptx
CH-4 (1).pptxCH-4 (1).pptx
CH-4 (1).pptx
 
lecture 6 bca 1 year-1.pptx
lecture 6 bca 1 year-1.pptxlecture 6 bca 1 year-1.pptx
lecture 6 bca 1 year-1.pptx
 
C statements
C statementsC statements
C statements
 
Absolute Java 5e Savitch Test Bank
Absolute Java 5e Savitch Test BankAbsolute Java 5e Savitch Test Bank
Absolute Java 5e Savitch Test Bank
 
basic of desicion control statement in python
basic of  desicion control statement in pythonbasic of  desicion control statement in python
basic of desicion control statement in python
 
Using decision statements
Using decision statementsUsing decision statements
Using decision statements
 
Decision Making and Branching in C
Decision Making and Branching  in CDecision Making and Branching  in C
Decision Making and Branching in C
 
Flow of control C ++ By TANUJ
Flow of control C ++ By TANUJFlow of control C ++ By TANUJ
Flow of control C ++ By TANUJ
 
Control Statement programming
Control Statement programmingControl Statement programming
Control Statement programming
 
Conditional statement in c
Conditional statement in cConditional statement in c
Conditional statement in c
 
Selection Statements in C Programming
Selection Statements in C ProgrammingSelection Statements in C Programming
Selection Statements in C Programming
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statements
 
Lecture 3 Conditionals, expressions and Variables
Lecture 3   Conditionals, expressions and VariablesLecture 3   Conditionals, expressions and Variables
Lecture 3 Conditionals, expressions and Variables
 
Flow control in c++
Flow control in c++Flow control in c++
Flow control in c++
 

More from Johnny Jean Tigas

All About Storyboarding in connection with Computer animation
All About Storyboarding in connection with Computer animationAll About Storyboarding in connection with Computer animation
All About Storyboarding in connection with Computer animationJohnny Jean Tigas
 
Algorithm, Pseudocode and Flowcharting in C++
Algorithm, Pseudocode and Flowcharting in C++Algorithm, Pseudocode and Flowcharting in C++
Algorithm, Pseudocode and Flowcharting in C++Johnny Jean Tigas
 
All about Network Models under Data Communications
All about Network Models under Data CommunicationsAll about Network Models under Data Communications
All about Network Models under Data CommunicationsJohnny Jean Tigas
 
National Learning Camp Assessment Orientation
National Learning Camp Assessment OrientationNational Learning Camp Assessment Orientation
National Learning Camp Assessment OrientationJohnny Jean Tigas
 
Configuring IPv4 and IPv6 Addressing to STEM
Configuring IPv4 and IPv6 Addressing to STEMConfiguring IPv4 and IPv6 Addressing to STEM
Configuring IPv4 and IPv6 Addressing to STEMJohnny Jean Tigas
 
A presentation design for the students in Science & Technologygy
A presentation design for the students in Science & TechnologygyA presentation design for the students in Science & Technologygy
A presentation design for the students in Science & TechnologygyJohnny Jean Tigas
 
Maintaining training facilities
Maintaining training facilitiesMaintaining training facilities
Maintaining training facilitiesJohnny Jean Tigas
 

More from Johnny Jean Tigas (8)

All About Storyboarding in connection with Computer animation
All About Storyboarding in connection with Computer animationAll About Storyboarding in connection with Computer animation
All About Storyboarding in connection with Computer animation
 
Algorithm, Pseudocode and Flowcharting in C++
Algorithm, Pseudocode and Flowcharting in C++Algorithm, Pseudocode and Flowcharting in C++
Algorithm, Pseudocode and Flowcharting in C++
 
All about Network Models under Data Communications
All about Network Models under Data CommunicationsAll about Network Models under Data Communications
All about Network Models under Data Communications
 
National Learning Camp Assessment Orientation
National Learning Camp Assessment OrientationNational Learning Camp Assessment Orientation
National Learning Camp Assessment Orientation
 
Configuring IPv4 and IPv6 Addressing to STEM
Configuring IPv4 and IPv6 Addressing to STEMConfiguring IPv4 and IPv6 Addressing to STEM
Configuring IPv4 and IPv6 Addressing to STEM
 
A presentation design for the students in Science & Technologygy
A presentation design for the students in Science & TechnologygyA presentation design for the students in Science & Technologygy
A presentation design for the students in Science & Technologygy
 
Maintaining training facilities
Maintaining training facilitiesMaintaining training facilities
Maintaining training facilities
 
Plan training session
Plan training sessionPlan training session
Plan training session
 

Recently uploaded

Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptxPoojaSen20
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 

Recently uploaded (20)

Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 

Switch Case Statement in C++ Programming Language

  • 1. Switch Case Statement Johnny Jean N. Tigas Zamboanga City High School
  • 2. - A sequence of statements use to verify equivalent values for each alternative.
  • 3. Syntax: switch (expression) { case constant_expression1: sequence_of_statements; break; case constant_expression2: sequence_of_statements; break; case constant_expression3: sequence_of_statements; break; … default: sequence_of_statements; }
  • 4. In response to this statement: a. It takes in the value of the expression. b. Then it will compare to the value of constant_expression1,if it is satisfied, then the statements belonging to constant_expression1 will be executed. c. If constant expression1 is not satisfied, it will continue on comparing all the constant_expressions until one is satisfied. d. If none is satisfied, the statement(s) under default will be executed.
  • 5. Sample Problem: A problem that lets you choose which data to input, that is ,either your first name, last name or middle name.
  • 6. #include<iostream.h> using namespace std; int main () { char name[10] int opt; cout<<“Selection…” <<“n[1] Firstname” <<“n[2] Lastname” <<“n[3] Middlename” <<“nYour choice:”; cin>>opt;
  • 7. switch(opt) { case 1: cout<<“nEnter Firstname:”; break; case 2: cout<<“nEnter Lastname:”; break; case 3: cout<<“nEnter Middlename:”; break; default: cout<<“nNone of the above.”; } cin>>name; cout<<“nnHello”<<name<<endl; return 0; }
  • 8. Possible Output: Selection... [1] Firstname [2] Lastname [3] Middlename Your choice: 2 Enter Lastname: Tigas Hello Tigas Please press any key to continue
  • 9. Assignment: Consider the problem with the secret number, if there are more than one secret number, you can use the switch to evaluate if the user have guessed one of the secret number. Assuming there are three (3) secret numbers, that is: 143,431 and 314;make a program to guess the 3 secret numbers.