Lab_4_2_Using_the_Selection_Control_Structures_if_and_if_else
Lab_4_2_Using_the_Selection_Control_Structures_if_and_if_else
Which path or branch the program will take in an if or if…else structure is determined by
evaluating a Boolean condition. The Boolean condition can be a simple Boolean expression
or a compound condition, that is, two or more Boolean expressions joined by logical
operators (the and or the or operators).
Objectives
In this lab, you will become acquainted with both the one-way alternative if selection
structure and the two-way alternative if…else selection structure. You will create a
program that uses the if and if…else structures.
int x = 6;
1. if (x > 10)
cout << “x is greater than 10\n”;
cout << “Selection allows decision making.\n”;
2. if (x = = 6)
cout << “A match is found.\n”;
cout << “Sequence continues after selection is
<< complete.\n”;
3. if (x < 8)
{
cout << “x is within the range.\n”;
cout << “This is a true statement.\n”;
}
cout << “And, after selection, the next statement is
<< executed.\n”;
6. if (x < 8)
{
cout << “x is within the range.\n”;
cout << “This is a true statement.\n”;
}
else
{
cout << “x is out of range.\n”;
cout << “This is a false statement.\n”;
}
cout << “After selection, the next statement is
executed.\n”;
7. if (x >= 5)
{
}
else
cout << “Have a good day.\n”;
Write your design in the following space. For your design, write an algorithm (an English
language description of the steps required to successfully write the program).
9b. Write the source code for the design you created in Exercise 9a and name it tickets.cpp.
9c. Enter, compile, link, and execute tickets.cpp. Copy the output and save it in a block
comment at the end of your program. Save tickets.cpp in the Chap04 folder of your
Student Data Files.
The following is a copy of the screen results that might appear after running your
program, depending on the data you entered.