








Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Dr. Mehandi Nandakumar delivered this lecture at Baddi University of Emerging Sciences and Technologies for Introduction to Computer Programming course. Its main points are: If, Statement, Selection, Decision, Block, Pseudocode, ATM, Withdrawal, Program, Nested
Typology: Slides
1 / 14
This page cannot be seen from the preview
Don't miss anything!









1
2
-^
4
The
if else
Statement
-^
Example: ATM Withdrawal program
5
7
Nested
if
s
-^
Another example #include
<iostream.h>
int
main() {
int
a,
b,
c;
cout
“Enter
three
numbers
a,
b,
c:\n”;
cin
a
b
c;
if (a==b)
if(b==c)
cout
“a,
b,
c are
equal\n”;
else
cout
“a
and
b are
different\n”;
return 0;
} • Let a=2, b=c=3. What’s printed?
8
The
if-else-if
Construction
-^
-^
10
The
switch
Statement
-^
If a large number of choices that all depend on one expression’svalue, better to use
switch
than the
if-else-if
construct
-^
-^
expression
must evaluate to an integer value (includes
characters);
constant
must be integer (or character) constant
11
The
switch
Statement
int
main() {
int
x=1; switch (x){
case 0:cout<<"zero \n";break;case 1:cout<<“one \n";break;default:cout<<“sorry! \n";break; } return
-^
char c = ‘M’; switch(c). What case will match now?
-^
case‘M’ will match too; so will case(‘L’ + 1)
-^
int x = 1, y = 2; switch(x<y). What case will match?
13
The
switch
Statement
-^
and
are optional but important.
-^
No two cases can have same value
-^
Can have same statements for multiple cases^ int
14
The
switch
Statement
int main(){
int i;for(i=0; i<5; i++){ switch(i){
case 0: cout << "less than 1\n";case 1: cout << "less than 2\n";case 2: cout << "less than 3\n";case 3: cout << "less than 4\n";case 4: cout << "less than 5\n";} cout << '\n'; } return 0;}
-^
-^
-^