Академический Документы
Профессиональный Документы
Культура Документы
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.
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.
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
28
UET Taxila Introduction to Programming Electrical Engineering Dept
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.
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.
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