C++ Conditional Statements
Introduction to ProgrammingIn every day life, we are often making decisions. We perform different tasks while taking decisions. For example, the statement ‘if the milk shop is open, bring one liter of milk while returning home from college’, involves this phenomenon.
In this statement, there is an element of decision making. We bring one litre of milk if the shop is open. And if the shop is closed, we come back to home without milk.
Thus we are making a decision on the condition that the shop is open. The decision- making process is everywhere in our daily life. We see that the college gives admission to a student if he has the required percentage in his previous examination and/or in the entry test. Similarly administration of a basketball team of the college decides that the students having height more than six feet can be members of the team.
In the previous lectures, we have written simple elementary programs. For writing interesting and useful programs, we have to introduce the decision making power in them. Now we will see what kind of decisions are there in programming and how these can be used.
Operators
| Types | Algebraic | In C language | Example | Meaning |
| Greater than | > | > | x > y | x is greater than y |
| Equal to | = | == | x == y | x is equal to y |
| Less than | < | < | x < y | x is less than y |
| Greater than or
equal to |
> | >= | x >= y | x is greater than or
equal to y |
| Less than or equal to | < | <= | x <= y | x is less than or equal to y |
| Not equal to | ≠ | != | x != y | x is not equal to y |
Sample Program
#include <iostream.h>
main()
{
int age1, age2; age1 = 12; age2 = 10;
if (age1 > age2)
cout << “Student 1 is older than student 2”;
}


Recent Comments