You are on page 1of 4

Lab # 05

Decisions

Nested branches
Nested if is an if statement that is the target of another if statement. Nested if statements
means an if statement inside another if statement. C++ allows us to nest if statements within if
statements.
Switch Statement
Switch statement compares the value of an expression against a list of integers or character
constants. The list of constants are listed using the "case" statement along with a "break"
statement to end the execution. If no conditions match then the code under the default
statement is executed.

switch(expression)
{
case constant1:
Statements
break
case constant2:
Statements
break
default
Statements
}
#include <iostream.h>
using namespace std;
int main(void)
{
int day;
cout << "Enter the day of the week between 1-7::";
cin >> day;
switch(day)
{
case 1:
cout << "Monday";
break;
case 2:
cout << "Tuesday";
break;
case 3:
cout << "Wednesday";
break;
case 4:
cout << "Thursday";
break;
case 5:
cout << "Friday";
break;
case 6:
cout << "Saturday";
break;
default:
cout << "Sunday";
break;
}
}
Lab Tasks:

1: If the variable divisor is not zero, divide the variable dividend by the divisor, and store the
result in quotient. If divisor is zero, assign it to quotient. Then print all the variables. [ Assume
that divisor and dividend are integers and quotient is a double ]

2: Write a program to compute tax based on the following table

You might also like