In this tutorial, we will learn about the if...else statement to create decision making programs with the help of many examples.
In computer programming, we use the if else statement to check a condition and if the condition is true, we run a block of statements (called the if-block).
For example, Student assigning grades (A, B, C,...) based on obtained marks.
- if the percentage is equal or above 80, assign grade A
- if the percentage is equal or above 60, assign grade B
- if the percentage is equal or above 50, assign grade C
- if the percentage is equal or above 40, assign grade D
- if the percentage is equal or above 33, assign grade E
Grade | Marks |
---|---|
A | >=80 |
B | >=60 |
C | >=50 |
D | >=40 |
E | >=33 |
There are three forms of if...else statements in C++.
- if statement
- if...else statement
- if...else if...else statement
0 Comments
if you have any doubt in programming concept please let me know