Conditional statements (2)

Slides:



Advertisements
Similar presentations
CS&E 1111 ExIFs IFs and Nested IFs in Excel Objectives: Using the If function in spreadsheets Nesting If functions.
Advertisements

Al-Karma Language School Computer Department Prep. 3.
1 Flowchart. 2 Flowchart: It is a diagram consists of symbolic block that represents the algorithm step by step Symbols of flowchart: 1. Terminal (start,
1 Flowchart If – Then – Else อนันต์ ผลเพิ่ม Anan Phonphoem
Introduction to Flowcharting A Supplement to Starting Out with C++, 4th Edition by Tony Gaddis Published by Addison-Wesley.
Pascal Programming Today Chapter 4 1 »Conditional statements allow the execution of one of a number of possible operations. »Conditional statements include:
1 CSC103: Introduction to Computer and Programming Lecture No 8.
Switch structure Switch structure selects one from several alternatives depending on the value of the controlling expression. The controlling expression.
School of Computing Science CMT1000 Ed Currie © Middlesex University 1 CMT1000: Introduction to Programming Ed Currie Lecture 5B: Branch Statements - Making.
1 Arithmetic in C. 2 Type Casting: STOPPED You can change the data type of the variable in an expression by: (data_Type) Variable_Name Ex: int a = 15;
Chapter 4 MATLAB Programming Logical Structures Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
ALGORITHMS AND FLOWCHARTS
Flowcharts! January 13, 2005 These are today’s notes! Do you think we will get more snow?
Decision II. CSCE 1062 Outline  Boolean expressions  switch statement (section 4.8)
Pascal language Slides of Omar Al-Nahal. Components of Pascal Language Components of Pascal Language 1. Pascal Character set: - English Letters. - Decimal.
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.
Multi Way Selection You can choose statement(s) to run from many sets of choices. There are two cases for this: (a)Multi way selection by nested IF structure.
PROBLEM SOLVING & ALGORITHMS CHAPTER 5: CONTROL STRUCTURES - SELECTION.
ALGORITHMS AND FLOWCHARTS CSCI 105 – Computer Fluency.
PHP-language, conditional statements Teppo Räisänen Principal Lecturer Oulu University of Applied Sciences School of Business and Information Management.
Conditional Structures UNIVERSITY OF THE PUNJAB (GUJRANWALA CAMPUS) ADNAN BABAR MT14028 CR
22/11/ Selection If selection construct.
Agenda Basic Logic Purpose if statement if / else statement
Lecture 2 Conditional Statement. chcslonline.org Conditional Statements in PHP Conditional Statements are used for decision making. Different actions.
Computer Science I: Understand how to evaluate expressions with DIV and MOD Random Numbers Reading random code Writing random code Odds/evens/…
Chapter 17 Supplement: Alternatives to IF-THEN/ELSE Processing STAT 541 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South.
CMP 131 Introduction to Computer Programming
2 nd Semester Module3 Selection Statement อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer.
Lecture 17 If-else statement Nothing is good or bad, but by comparison. Thomas Fuller, Gnomologia.
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
Looping(1) For … to … do... Can you do this? Write a program to display:
PHP-language, conditional statements
Decision making If.. else statement.
INC 161 , CPE 100 Computer Programming
Lesson Objectives Aims To be able to write an algorithm in Pseudo Code
VB.Net Programming Console Application
Chapter 4 MATLAB Programming
EKT150 INTRODUCTION TO COMPUTER PROGRAMMING
Algorithms and Flowcharts
SELECTION STATEMENTS (1)
ALGORITHMS AND FLOWCHARTS
Making Decisions in a Program
Program options Write a program for one of the following
Notes Over 2.1 Function {- 3, - 1, 1, 2 } { 0, 2, 5 }
ICS 3U Tuesday, September 21st.
And now for something completely different . . .
Chapter 9 Control Structures.
SELECTION STATEMENTS (2)
ALGORITHMS AND FLOWCHARTS
If selection construct
CSE 1020:Control Structure
Decision making If statement.
If selection construct
Selection Control Structure
Visual Basic – Decision Statements
Selection Statements.
Chapter 5: Control Structure
SELECTIONS STATEMENTS
Computer Science 1 Warm-up: True/False Dry Run
Flowchart.
CS2011 Introduction to Programming I Selections (I)
Chapter 4: Boolean Expressions, Making Decisions, and Disk Input and Output Prof. Salim Arfaoui.
Computer Science 1 For..do loop Dry Run Take notes on the For loop
CHAPTER 5: Control Flow Tools (if statement)
Developing a Program.
CS150 Introduction to Computer Science 1
Computer Science I: Get out your notes.
Program options Write a program for one of the following
HNDIT11034 More Operators.
Presentation transcript:

Conditional statements (2) IF mark>=50 THEN writeln(‘pass’) ELSE writeln(‘work hard’);

????? Consider the following flowchart: Get mark N Y mark>=50? Display ‘pass’ Display ‘fail’ Display ‘Bye Bye’ END

Get mark N Y mark>=50? Display ‘pass’ Display ‘fail’ Display ‘Bye Bye’ END

readln(mark) writleln(‘fail’) writeln(‘pass’) writeln(‘Bye Bye’); END

write(‘Please enter your mark:’); readln(mark); if (name >= 50) then writeln(‘pass’) else writeln(‘fail’); writeln(‘Bye Bye!’);

program pass; var mark:integer; begin write(‘Please enter your mark:’); readln(mark); if (name >= 50) then writeln(‘pass’) else writeln(‘fail’); writeln(‘Bye Bye!’); end.

(Alternative) program pass; var mark:integer; begin write(‘Please enter your mark:’); readln(mark); if (name >= 50) then writeln(‘pass’); if (name <50) then writeln(‘fail’); writeln(‘Bye Bye!’); end.

Syntax Example if <<Boolean expression>> then <<statement>> else <<statement>>; Example if (sex=‘F’) or (sex=‘M’) then number:=number + 1 else writeln(‘invalid input’);

Exercise 1 Please enter a number:19 It is not divisible by 4. Write a program to get a number from the user and tell the user whether it is divisible by 4. Make use of if…then…else statement. Sample output: Please enter a number:19 It is not divisible by 4. Please enter a number:36 It is divisible by 4.

Answer program divisible; var number:integer; begin write(‘Please enter a number:’); readln(number); if (number mod 4)=0 then writeln(‘It is divisible by 4’) else writeln(‘It is not divisible by 4’); end.

Exercise 2 Please enter your mark:85 Your grade is B Write a program to get a mark from the user and display the corresponding grade according table: 91-100 => A 81-90 => B 66-80 => C 51-65 => D 0-50 => F Make use of if…then…else statement. Sample output: Please enter your mark:85 Your grade is B

Answer program divisible; var mark:integer; grade:char; begin write(‘Please enter your mark:’); readln(mark); if (mark<=100) then if (mark>=91) then grade:=‘A’ else if (mark>=81) then grade:=‘B’ else if (mark>=66) then grade:=‘C’ else if (mark>=51)then grade:=‘D’ else if (mark>=0)then grade:=‘F’; writeln(‘Your grade is ‘,grade); end.