Week 3 Selection Structures

Week 3 Selection Structures - String status NumCds,...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Reading on Selection Str Table of Contents: Single Alternative If-Structures Double Alternative If-Structures A single-alternative if structure is a selection structure with only one outcome. The outcome executes only if the The true conditional branch contains the outcome which executes when a condition evaluates t An entry point occurs where the vertical line intersects with the top of the if-structure’s diamon An exit point occurs where the vertical line intersects with the button of the if-structure’s diamo General Form of a Single Alternative If-structure o The condition goes in a diamond, without the If or Then keywords. o If the condition is true, the solution branches to the right. This is called the “True conditional branch”. o The true conditional branch contains one or more outcomes. o When finished, the true conditional branch exits the structure and proceeds to the next step. o If the condition is false, the solution ignores the branch, and leaves through the exit point Outcome in the true conditional branch ge that says, “You can apply for a government grant”. If your income is greater than or equal to $17000, the solution displays no such message. Regar Outcome in the true conditional branch decimal taxrate decimal result get income, taxrate if income < 17000 then display eligibility message Endif result = income * taxrate display result Stop The if-structure begins on the same indentation level as the line above it This outcome has been indented to show that it belongs to the true conditional branch ment media (compact discs and DVD’s). The solution asks how many compact discs you have, the average cost of a compact disk, and whether y ing the number of CD’s by the average cost of a CD, and displays the answer. erage cost of a DVD, displaying the result of the calculation. dcalc is a Boolean, because users enter “true” if they want to do the DVD calculations, and “False” if they don’t. true conditional branch CdTotalValue = NumCds* CdAvgPrice Display CdTotalvalue If DvdCalc = true then Get NumDvds, DvdAvgPrice DVDtotalvalue = NumDvds* DvdAvgPrice Display DVDTotalValue End if Display “Calculations Complete” Stop re contains two outcomes. The first outcome executes if the condition is true. The second outcome executes when the condition evaluates to false. A false conditional branch contains an outcome which executes when a condition evaluates to false. General Form of a Double Alternative If-Structure Example 5.05.01 The structure starts with a diamond Inside the diamond is a condition as usual The structure has two branches – the true and false conditional branches. Each branch has its own set of flowcharting symbols (outcomes) Entry Point Exit Point r’s status is “preferred” the program displays “Price is $8”. If the customer’s status is not preferred, the program displays “Price is $10”. ys “End of Program”.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 07/27/2009 for the course BIS 311 taught by Professor Marshburn during the Fall '08 term at DeVry Cincinnati.

Page1 / 14

Week 3 Selection Structures - String status NumCds,...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online