Вы находитесь на странице: 1из 7

UET Taxila Introduction to Programming Electrical Engineering Dept

Objective
Make use of
If Statement
Sometimes we may only want a portion of code executed under certain
conditions. To do so, we use conditional statements. For example, if you
are writing a payroll program to compute wages, then the program should
only compute overtime pay if the employee worked more than 40 hours in a
given week. Otherwise, when the program is executed the overtime portion
of the code should be bypassed. An if statement is one kind of conditional
statement.

If-Else Structure
It is used for making two-way decisions. In this statement, one condition
and two blocks of statement are given. Either one of the two blocks of
statement is executed after a condition.
The if-else statement tests the given relation condition. If the condition is
true then the first block of statement is executed. If the condition is false,
the first block of statement is ignored and the second block following the
else is executed.

Nested if-else when an if statement is used within another if statement,


it is called the nested if statement. The nested if statement is used for
multi-way decision-making.

26
UET Taxila Introduction to Programming Electrical Engineering Dept

Program No.17
Write a program in C++ that take input of three integers numbers from
user. Find the largest number among three of them.

OutPut of Program No.17

27
UET Taxila Introduction to Programming Electrical Engineering Dept

Program No.18
Write a program in C++ using if/else operator with nested statements to
find the grade of a student.
The detail is as follow.
grade >= 90 Grade A
grade >= 80 Grade B
grade >=70 Grade C
grade >=60 Grade D

OutPut of Program No.18

28
UET Taxila Introduction to Programming Electrical Engineering Dept

Program No.19

Write a program in C++ to input a single character and print a message It


is vowel" if it is vowel otherwise print message "It is a "constant Use if-
else structure and OR (||) operator only

OutPut of Program No.19

29
UET Taxila Introduction to Programming Electrical Engineering Dept

Program No.20

Write a Program in C++ that take an Integer Value from the user and tell
that the number is EVEN or ODD.

OutPut of Program No.20

30
UET Taxila Introduction to Programming Electrical Engineering Dept

Program No.21

Write a program in C++ that take a single character from the user, and tells
it's a Small Letter or it's a CAPITAL letter using nested if statement only.

OutPut of Program No.21

31
UET Taxila Introduction to Programming Electrical Engineering Dept

Program No.22

Make a program in C ++ that tells the form of Water whether it is Ice, Water
or Steam. Display the menu also as under.
HINT: Temperature Less than 0 = ICE
Temperature Greater than 0 & Less than 100 = Water
Temperature Greater than 100 = STEAM
OutPut of Program No.22

32

Вам также может понравиться