SlideShare a Scribd company logo
2
Most read
7
Most read
9
Most read
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

PPTX
Programming Fundamentals lec 08 .pptx
PPTX
Final project powerpoint template (fndprg) (1)
PPTX
POLITEKNIK MALAYSIA
PPTX
Switch.pptx
PPTX
Introduction to Selection control structures in C++
PPTX
Chapter 3 Conditional Statements&Looping (1).pptx
PPTX
week 3 Programming lecture 06 (1) .pptx
PPTX
Powerpoint presentation final requirement in fnd prg
Programming Fundamentals lec 08 .pptx
Final project powerpoint template (fndprg) (1)
POLITEKNIK MALAYSIA
Switch.pptx
Introduction to Selection control structures in C++
Chapter 3 Conditional Statements&Looping (1).pptx
week 3 Programming lecture 06 (1) .pptx
Powerpoint presentation final requirement in fnd prg

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

PPT
Final requirement
PPT
Loops_and_FunctionsWeek4_0.ppt
PPTX
Final requirement
PDF
Control statements-Computer programming
PPTX
Programming Fundamentals
 
PPTX
Switch case.pptx
PDF
Lecture13 control statementswitch.ppt
PPTX
Control Structures.pptx
PPTX
Lab # 3
PPT
4b C switch structure .ppt
PPT
My programming final proj. (1)
PPTX
Intruduction conditional statement
PDF
Principals of Programming in CModule -5.pdfModule_2_P2 (1).pdf
PPTX
Intro To C++ - Class 13 - Char, Switch, Break, Continue, Logical Operators
PPTX
Presentation on C Switch Case Statements
PPT
Lecture#4 Algorithm and computing
PPSX
Ramirez slideshow
PDF
controlflowwSoftware Development Fundamentals (SDF) – I ODD 2024 Jaypee Insti...
PPT
conditional.ppt
PPTX
C PROGRAMMING p-3.pptx
Final requirement
Loops_and_FunctionsWeek4_0.ppt
Final requirement
Control statements-Computer programming
Programming Fundamentals
 
Switch case.pptx
Lecture13 control statementswitch.ppt
Control Structures.pptx
Lab # 3
4b C switch structure .ppt
My programming final proj. (1)
Intruduction conditional statement
Principals of Programming in CModule -5.pdfModule_2_P2 (1).pdf
Intro To C++ - Class 13 - Char, Switch, Break, Continue, Logical Operators
Presentation on C Switch Case Statements
Lecture#4 Algorithm and computing
Ramirez slideshow
controlflowwSoftware Development Fundamentals (SDF) – I ODD 2024 Jaypee Insti...
conditional.ppt
C PROGRAMMING p-3.pptx
Ad

More from Johnny Jean Tigas (8)

PPTX
All About Storyboarding in connection with Computer animation
PPT
Algorithm, Pseudocode and Flowcharting in C++
PPT
All about Network Models under Data Communications
PPTX
National Learning Camp Assessment Orientation
PPTX
Configuring IPv4 and IPv6 Addressing to STEM
PPTX
A presentation design for the students in Science & Technologygy
DOCX
Maintaining training facilities
DOC
Plan training session
All About Storyboarding in connection with Computer animation
Algorithm, Pseudocode and Flowcharting in C++
All about Network Models under Data Communications
National Learning Camp Assessment Orientation
Configuring IPv4 and IPv6 Addressing to STEM
A presentation design for the students in Science & Technologygy
Maintaining training facilities
Plan training session
Ad

Recently uploaded (20)

PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
Piense y hagase Rico - Napoleon Hill Ccesa007.pdf
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
Nursing Management of Patients with Disorders of Ear, Nose, and Throat (ENT) ...
PPTX
Introduction and Scope of Bichemistry.pptx
PPTX
Revamp in MTO Odoo 18 Inventory - Odoo Slides
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
The Final Stretch: How to Release a Game and Not Die in the Process.
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Business Ethics Teaching Materials for college
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
Onica Farming 24rsclub profitable farm business
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
O7-L3 Supply Chain Operations - ICLT Program
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Piense y hagase Rico - Napoleon Hill Ccesa007.pdf
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Nursing Management of Patients with Disorders of Ear, Nose, and Throat (ENT) ...
Introduction and Scope of Bichemistry.pptx
Revamp in MTO Odoo 18 Inventory - Odoo Slides
O5-L3 Freight Transport Ops (International) V1.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
Week 4 Term 3 Study Techniques revisited.pptx
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
The Final Stretch: How to Release a Game and Not Die in the Process.
Anesthesia in Laparoscopic Surgery in India
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Business Ethics Teaching Materials for college
STATICS OF THE RIGID BODIES Hibbelers.pdf
Onica Farming 24rsclub profitable farm business
human mycosis Human fungal infections are called human mycosis..pptx
O7-L3 Supply Chain Operations - ICLT Program

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.