0% found this document useful (0 votes)
40 views4 pages

Lab # 05 Decisions: Nested Branches

The document discusses nested if statements, switch statements, and provides an example switch statement program to output the day of the week based on a number input. It also provides a task to write an if/else statement to check for division by zero and calculate tax based on a table.

Uploaded by

irum jafri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views4 pages

Lab # 05 Decisions: Nested Branches

The document discusses nested if statements, switch statements, and provides an example switch statement program to output the day of the week based on a number input. It also provides a task to write an if/else statement to check for division by zero and calculate tax based on a table.

Uploaded by

irum jafri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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