Professional Documents
Culture Documents
4
DECISION CONTROL
STRUCTURE
{statement1;statement2;statement3;}
1.If statement
2.If-else statement
3.Nested if-else statement
1. #include<iostream>
2. using namespace std;
3. main()
4. {
5. int age = 21;
6. if (age = = 85)
7. {
8. cout <<" You have lived through a lot ";
9. }
10. }
11.
The program doesn’t do anything if the age is
not equal to 85.
In the second run the condition evaluates to false, since 200( the value of
quantity) isn't greater than 1000, Thus dis which earlier was set to 0
remains 0, and hence the expression after the minus sign evaluates to zero
thereby offering no discount
1. #include<iostream>
2. using namespace std;
3. main()
4. {
5. int num;
6. cout <<"Enter your number“<<endl;
7. cin >> num;
8. if (num > 0)
9. {
10. cout << " More than 0 "<<"\n";
11. }
12. else
13. {
14. cout <<"Less or equal to 0"<<"\n";
15. }
16. // No matter what the number was the following statement is executed
17. cout <<"\n\n Thanks for your time\n";
18. }
If his basic salary is less than frw 1500, then HRA = 10%
of basic salary and TA=90% of basic. If his salary is
either equal to or above frw 1500, then HRA= frw 500
and TA = 98% of basic salary.
• #include<iostream>
• using namespace std;
• main()
• {
• float bs,gs,ta,hra;
• cout <<"Enter the basic salary";
• cin >> bs;
• gs = bs + hra + ta;
If (condition)
statement
Else if (condition)
statement
Else if (condition)
statement
Else if (condition)
statement
Else
statement
return 0;
}
#include<iostream>
using namespace std;
main()
{
int i;
1. If((a>b) &&(b>c))
2. d=a+b;
3. Else
4. d=a-b;
9. per =(m1+m2+m3+m4+m5)/5;
! Logical NOT
*/% Arithmetic and Modulus
+- Arithmetic
<> <= >= Relational
== != Relational
&& Logical AND
|| Logical OR
= Assignment
Decision Control Structure 26
Assignment one –
Decision Control
Structures