Computer Science: A Structured Programming Approach Using C1 5-2 Two-Way Selection The decision is described to the computer as a conditional statement.

Slides:



Advertisements
Similar presentations
Decision Structures - If / Else If / Else. Decisions Often we need to make decisions based on information that we receive. Often we need to make decisions.
Advertisements

IF statement (i) Single statement. IF ( logical expression ) statement Example: read(*,*) a if (a. lt. 0) a = -a write(*,*) a Or read(*,*) a if (a < 0)
Chapter 13 Control Structures. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display Control Structures Conditional.
The If Then Else Statement Using JavaScript TIP The If Statement is the fundamental control structure that allows branches in the flow of control in a.
1 CSC103: Introduction to Computer and Programming Lecture No 8.
Chapter 4 Control Structures I. Objectives ► Examine relational and logical operators ► Explore how to form and evaluate logical (Boolean) expressions.
July 13 th.  If/ Else if / Else  Variable Scope  Nested if/else's  Switch statements  Conditional Operator.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
Decisions (Conditional Programming) Chapter 5 (Sec. 5.1 & 5.2)
1 Lecture 8:Control Structures I (Selection) (cont.) Introduction to Computer Science Spring 2006.
2-1 Making Decisions Sample assignment statements PayAmount = Hours * Rate PayAmount = 40*Rate + (Hours – 40)*Rate*1.5.
true (any other value but zero) false (zero) expression Statement 2
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Conditional Statements Control Structures.
Tutorial 4 Decision Making with Control Structures and Statements Section A - Decision Making JavaScript Tutorial 4 -Decision Making with Control.
Chapter 4: Control Structures: Selection
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand basic loop concepts: ■ pretest loops and post-test loops ■ loop.
CHAPTER 4: CONDITIONAL STRUCTURES Introduction to Computer Science Using Ruby (c) 2012 Ophir Frieder et al.
1 Chapter 4: Selection Structures. In this chapter, you will learn about: – Selection criteria – The if-else statement – Nested if statements – The switch.
Chapter 4: Control Structures I J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design,
Conditional Statements For computer to make decisions, must be able to test CONDITIONS IF it is raining THEN I will not go outside IF Count is not zero.
1 CSC 1401 S1 Computer Programming I Hamid Harroud School of Science and Engineering, Akhawayn University
WEEK8WEEK8 WEEK8WEEK8 Selection Making Decisions 1 Kulliyyah of ICT INFO 2020 Structured Programming Language.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To be able to list and describe the six expression categories ❏ To understand.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 4 Decision.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand how decisions are made in a computer ❏ To understand the logical.
If…else statements. Boolean Expressions Boolean expression - An expression whose value is either true or false true = 1 false = 0 Datatype: boolean.
A First Book of ANSI C Fourth Edition Chapter 4 Selection.
Computer Science: A Structured Programming Approach Using C1 5-3 Multiway Selection In addition to two-way selection, most programming languages provide.
1 2. Program Construction in Java. 2.4 Selection (decisions)
1 Objectives ❏ To understand how decisions are made in a computer ❏ To understand the logical operators: and, or, and not ❏ To understand how a C program.
Programming 1 DCT 1033 Control Structures I (Selection) if selection statement If..else double selection statement Switch multiple selection statement.
Computer Science: A Structured Programming Approach Using C1 5-2 Two-Way Selection The decision is described to the computer as a conditional statement.
© Janice Regan, CMPT 128, Jan CMPT 128: Introduction to Computing Science for Engineering Students Introduction to branching.
Selection-making Decisions Selection allows you to choose between two or more possible program flow --- it lets you make decisions in your program. Examples.
Chapter 4 Control Structures I. Chapter Objectives Learn about control structures Examine relational and logical operators Explore how to form and evaluate.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
CPS120: Introduction to Computer Science Decision Making in Programs.
8. DECISION STRUCTURES Rocky K. C. Chang October 18, 2015 (Adapted from John Zelle’s slides)
1 Conditional Statements + Loops ผศ. ดร. อนันต์ ผลเพิ่ม Anan Phonphoem
Lesson thirteen Conditional Statement "if- else" ©
# 1# 1 CS 105 Spring 2010 If, If Else Statements What does If / Then do? Is Else necessary? What is Pseudocode? Does the computer skip lines of code?
CPS120: Introduction to Computer Science Decision Making in Programs.
Decision Making and Branching
Computer Science: A Structured Programming Approach Using C1 5-5 Incremental Development Part II In Chapter 4, we introduced the concept of incremental.
CHAPTER 3 CONTROL STRUCTURES ( SELECTION ) I NTRODUCTION T O C OMPUTER P ROGRAMMING (CSC425)
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 2: Control Structures (Selection & Repetition)
Conditional Statements A conditional statement lets us choose which statement will be executed next Conditional statements give us the power to make basic.
Silberschatz and Galvin  C Programming Language Decision making in C Kingdom of Saudi Arabia Ministry of Higher Education Al-Majma’ah University.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand how decisions are made in a computer ❏ To understand the logical.
AND.
Sequence, Selection, Iteration The IF Statement
Introduction to C++ Programming Language
Section 7.1 Logical Operators
Statements (6 of 6) A statement causes an action to be performed by the program. It translates directly into one or more executable computer instructions.
Selection—Making Decisions
Topics discussed in this section:
Control Structures.
Chapter 6 Repetition Objectives ❏ To understand basic loop concepts:
Structure of a C Program
Topics discussed in this section:
Topics discussed in this section:
2-1 Making Decisions Sample assignment statements
Chapter 4: Decision Structures and Boolean Logic
Visual Basic – Decision Statements
Topics discussed in this section:
Section 3.2 Truth Tables for Negation, Conjunction, and Disjunction
Computer Programming Basics
Selection—Making Decisions
Topics discussed in this section:
Chapter 4: Decision Structures and Boolean Logic
Presentation transcript:

Computer Science: A Structured Programming Approach Using C1 5-2 Two-Way Selection The decision is described to the computer as a conditional statement that can be answered either true or false. If the answer is true, one or more action statements are executed. If the answer is false, then a different action or set of actions is executed. if…else and Null else Statement Nested if Statements and Dangling else Problem Simplifying if Statements Conditional Expressions Topics discussed in this section:

Computer Science: A Structured Programming Approach Using C2 FIGURE 5-6 Two-way Decision Logic

Computer Science: A Structured Programming Approach Using C3 FIGURE 5-7 if...else Logic Flow

Computer Science: A Structured Programming Approach Using C4 Table 5-2Syntactical Rules for if…else Statements

Computer Science: A Structured Programming Approach Using C5 FIGURE 5-8 A Simple if...else Statement

Computer Science: A Structured Programming Approach Using C6 FIGURE 5-9 Compound Statements in an if...else

Computer Science: A Structured Programming Approach Using C7 FIGURE 5-10 Complemented if...else Statements

Computer Science: A Structured Programming Approach Using C8 FIGURE 5-11 A Null else Statement

Computer Science: A Structured Programming Approach Using C9 FIGURE 5-12 A Null if Statement

Computer Science: A Structured Programming Approach Using C10 PROGRAM 5-3Two-way Selection

Computer Science: A Structured Programming Approach Using C11 PROGRAM 5-3Two-way Selection

Computer Science: A Structured Programming Approach Using C12 FIGURE 5-13 Nested if Statements

Computer Science: A Structured Programming Approach Using C13 PROGRAM 5-4Nested if Statements

Computer Science: A Structured Programming Approach Using C14 PROGRAM 5-4Nested if Statements

Computer Science: A Structured Programming Approach Using C15 else is always paired with the most recent unpaired if. Note

Computer Science: A Structured Programming Approach Using C16 FIGURE 5-14 Dangling else

Computer Science: A Structured Programming Approach Using C17 FIGURE 5-15 Dangling else Solution

Computer Science: A Structured Programming Approach Using C18 Table 5-3Simplifying the Condition

Computer Science: A Structured Programming Approach Using C19 FIGURE 5-16 Conditional Expression

Computer Science: A Structured Programming Approach Using C20 Table 5-4Examples of Marginal Tax Rates

Computer Science: A Structured Programming Approach Using C21 FIGURE 5-17 Design for Calculate Taxes

Computer Science: A Structured Programming Approach Using C22 FIGURE 5-18 Design for Program 5-5 (Part I)

Computer Science: A Structured Programming Approach Using C23 FIGURE 5-18 Design for Program 5-5 (Part II)

Computer Science: A Structured Programming Approach Using C24 FIGURE 5-18 Design for Program 5-5 (Part III)

Computer Science: A Structured Programming Approach Using C25 PROGRAM 5-5Calculate Taxes

Computer Science: A Structured Programming Approach Using C26 PROGRAM 5-5Calculate Taxes

Computer Science: A Structured Programming Approach Using C27 PROGRAM 5-5Calculate Taxes

Computer Science: A Structured Programming Approach Using C28 PROGRAM 5-5Calculate Taxes

Computer Science: A Structured Programming Approach Using C29 PROGRAM 5-5Calculate Taxes

Computer Science: A Structured Programming Approach Using C30 PROGRAM 5-5Calculate Taxes

Computer Science: A Structured Programming Approach Using C31 PROGRAM 5-5Calculate Taxes

Computer Science: A Structured Programming Approach Using C32 PROGRAM 5-5Calculate Taxes

Computer Science: A Structured Programming Approach Using C33 PROGRAM 5-5Calculate Taxes

Computer Science: A Structured Programming Approach Using C34 PROGRAM 5-5Calculate Taxes