This presentation includes custom animations. To view the animations, you must view the presentation in Slide Show mode and activeX controls must be allowed.

Slides:



Advertisements
Similar presentations
ALGORITHMS AND FLOWCHARTS
Advertisements

CS101: Introduction to Computer programming
ALGORITHMS AND FLOWCHARTS
PROBLEM SOLVING TECHNIQUES
Logic & program control part 3: Compound selection structures.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 4 Making Decisions in a Program.
This presentation includes custom animations. To view the animations, you must view the presentation in Slide Show mode and activeX controls must be allowed.
Chapter 2: Problem Solving
This presentation includes custom animations. To view the animations, you must view the presentation in Slide Show mode and activeX controls must be allowed.
Pascal Programming Today Chapter 4 1 »Conditional statements allow the execution of one of a number of possible operations. »Conditional statements include:
This presentation includes custom animations. To view the animations, you must view the presentation in Slide Show mode and activeX controls must be allowed.
Fall 2004ENGR 111A MatLab – Palm Chapter 4, Part 2 The if and switch structure Class 10.1 Sections: 4.4 and 4.6.
This presentation includes custom animations. To view the animations, you must view the presentation in Slide Show mode and activeX controls must be allowed.
This presentation includes custom animations. To view the animations, you must view the presentation in Slide Show mode and activeX controls must be allowed.
This presentation includes custom animations. To view the animations, you must view the presentation in Slide Show mode and activeX controls must be allowed.
This presentation includes custom animations. To view the animations, you must view the presentation in Slide Show mode and activeX controls must be allowed.
This presentation includes custom animations. To view the animations, you must view the presentation in Slide Show mode and activeX controls must be allowed.
This presentation includes custom animations. To view the animations, you must view the presentation in Slide Show mode and activeX controls must be allowed.
This presentation includes custom animations. To view the animations, you must view the presentation in Slide Show mode and activeX controls must be allowed.
Compunet Corporation1 Programming with Visual Basic.NET Selection Structure If-Else Week 4 Tariq Ibn Aziz.
This presentation includes custom animations. To view the animations, you must view the presentation in Slide Show mode and activeX controls must be allowed.
This presentation includes custom animations. To view the animations, you must view the presentation in Slide Show mode and activeX controls must be allowed.
This presentation includes custom animations. To view the animations, you must view the presentation in Slide Show mode and activeX controls must be allowed.
Chapter 2: Input, Processing, and Output
An Introduction to Programming with C++ Fifth Edition Chapter 6 More on the Selection Structure.
This presentation includes custom animations. To view the animations, you must view the presentation in Slide Show mode and activeX controls must be allowed.
This presentation includes custom animations. To view the animations, you must view the presentation in Slide Show mode and activeX controls must be allowed.
This presentation includes custom animations. To view the animations, you must view the presentation in Slide Show mode and activeX controls must be allowed.
This presentation includes custom animations. To view the animations, you must view the presentation in Slide Show mode and activeX controls must be allowed.
Chapter 3 Planning Your Solution
ALGORITHMS AND FLOWCHARTS
Computer Programming 12 Lesson 2 - Organizing the Problem By Dan Lunney.
DCT 1123 Problem Solving & Algorithms
System Implementation System Implementation - Mr. Ahmad Al-Ghoul System Analysis and Design.
PROGRAMMING, ALGORITHMS AND FLOWCHARTS
Visual C# 2005 Decision Structures. Visual C# Objectives Understand decision making Learn how to make decisions using the if statement Learn how.
Institute for Personal Robots in Education (IPRE)‏ CSC 170 Computing: Science and Creativity.
Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and Elizabeth Drake Chapter 2: Flowcharts.
5-1 Repetition Statements Repetition statements allow us to execute a statement multiple times Often they are referred to as loops Like conditional statements,
Conditions. Objectives  Understanding what altering the flow of control does on programs and being able to apply thee to design code  Look at why indentation.
Lecture 2: Logical Problems with Choices. Problem Solving Before writing a program Have a thorough understanding of the problem Carefully plan an approach.
1 Boolean Expressions to Make Comparisons Boolean expression –Represents only one of two states –Expression evaluates to either true or false Expressions.
An Introduction to Programming with C++ Sixth Edition Chapter 7 The Repetition Structure.
Chapter 2 Pseudocode. Objectives To introduce common words, keywords and meaningful names when writing pseudocode To define the three basic control structures.
ALGORITHMS AND FLOWCHARTS CSCI 105 – Computer Fluency.
Algorithmic state machines
Chapter Topics 2.1 Designing a Program 2.2 Output, Input, and Variables 2.3 Variable Assignment and Calculations 2.4 Variable Declarations and Data Types.
The Department of Engineering Science The University of Auckland Welcome to ENGGEN 131 Engineering Computation and Software Development Lecture 2 Debugging,
Chapter 7: The Repetition Structure Introduction to Programming with C++ Fourth Edition.
ALGORITHMS AND FLOWCHARTS. A typical programming task can be divided into two phases: Problem solving phase  produce an ordered sequence of steps that.
An Introduction to Programming with C++ Sixth Edition Chapter 5 The Selection Structure.
ALGORITHMS AND FLOWCHARTS
More on the Selection Structure
Chapter 2: Input, Processing, and Output
The Selection Structure
Chapter Topics 2.1 Designing a Program 2.2 Output, Input, and Variables 2.3 Variable Assignment and Calculations 2.4 Variable Declarations and Data Types.
Programming Fundamentals
Microsoft Visual Basic 2005 BASICS
ALGORITHMS AND FLOWCHARTS
Lecture 2: Logical Problems with Choices
ALGORITHMS AND FLOWCHARTS
ALGORITHMS AND FLOWCHARTS
MatLab – Palm Chapter 4, Part 2 The if and switch structure
MatLab – Palm Chapter 4, Part 2 The if and switch structure
ICT Programming Lesson 3:
Boolean Expressions to Make Comparisons
ICT Gaming Lesson 2.
Chapter 2: Input, Processing, and Output
Structural Program Development: If, If-Else
Presentation transcript:

This presentation includes custom animations. To view the animations, you must view the presentation in Slide Show mode and activeX controls must be allowed. If you have opened this lesson in PowerPoint, use the PowerPoint menus to view it in slide show mode. If you have opened this lesson in a browser and see a bar similar to that below, click on the Slide Show icon A notice similar to the one below may appear warning that ActiveX or other scripts are disabled. Enable the controls for this website in order to see the animations.

IF statements This slide show introduces the IF logic structure and describes how flowcharts are used to document if statements Christine S. Wolfe Ohio University Lancaster 2008-Aug-01 Vocabulary: algorithm annotation if else

In pseudocode the if statement is written as if (logical (Boolean) expression) statement(s) to execute if expression is true else statement(s) to execute if expression is false end if The else clause is optional The IF logic structure forces the program to take one of 2 paths based on the logical value of an expression. Click Tip The syntax of the if statement in ANSI C is if (logical (Boolean) expression) { statement(s) to execute if expression is true } else { statement(s) to execute if expression is false }

if logical exp statements to execute if expression is true statements to execute if expression is false T F The diamond symbol is used to flowchart a logical expression. When used to diagram an if condition, there is exactly one inflow and two outflows. One of the outflows is labeled "T" and points to the next instruction to be executed whenever the condition is True. The other outflow is labeled "F" and points to the next instruction to be executed whenever the condition is False. if logical exp statements to execute if expression is false statements to execute if expression is true F T Typically, the paths link up again after one of the alternates is executed. Click Tip it doesn't matter which outflow is T and which is F as long as they point to the appropriate instructions. Generally, programmers choose the layout that best fits on the paper.

5 X > 10 T F PRINT “It’s True” PRINT “It’s False” x = 1; if (x > 10) { printf(“It’s True”); } else { printf(“It’s False”); } It’s TrueIt’s False x = 20;x = 10; 12010

IF logical exp statements to execute if expression is true statements to execute if expression is false T F Sometimes, you want the program to do something special when a condition is true but, there is nothing special to do when the condition is false. Because the else, or False path is optional, no statements are required along the F path.

Calculate the interest charged on an invoice. The interest rate is determined by the customer's credit status as determined by the vendor as shown in the chart below: Credit StatusInterest Rate A5 % B10% C12% Example 1: Customer Bob has a credit status of A and orders $ of merchandise. The interest charged on his order is $50.00 ( * 0.05) Example 2: Customer Alan has a credit status of C and orders $ of merchandise. The interest charged on his order is $60.00 ( * 0.12)

The problem can be solved by using a series of IF statements. START GET CreditStatus GET TotalMerchandise if CreditStatus == 'A' CALCULATE Interest = TotalMerchandise * 0.05 end if if CreditStatus == 'B' CALCULATE Interest = TotalMerchandise * 0.10 end if if CreditStatus == 'C' CALCULATE Interest = TotalMerchandise * 0.12 end if PRINT Interest STOP

main() IF CreditStatus == 'A' Interest = TotalMerchandise * 0.05 GET CreditStatus GET Total Merchandise PRINT Interest STOP A IF CreditStatus == 'B' Interest = TotalMerchandise * 0.10 IF CreditStatus == 'C' Interest = TotalMerchandise * 0.12 N Y B N Y A N Y B