Selection 03/7/15. Programs Get help if you are not getting homework. –It's 40% of your grade.

Slides:



Advertisements
Similar presentations
ALGORITHMS - PART 2 CONDITIONAL BRANCH CONTROL STRUCTURE
Advertisements

Making Choices in C if/else statement logical operators break and continue statements switch statement the conditional operator.
C++ Basics March 10th. A C++ program //if necessary include headers //#include void main() { //variable declaration //read values input from user //computation.
Making Decisions in Python Sec 9-10 Web Design. Objectives The student will: Understand how to make a decision in Python Understand the structure of an.
CS0007: Introduction to Computer Programming
Problem Solving and Program Design in C (5th Edition) by Jeri R. Hanly and Elliot B. Koffman Chapter 4 (Conditional Statements) © CPCS
 2002 Prentice Hall. All rights reserved Control Structures 3 control structures –Sequential structure Built into Python –Selection structure The.
CS107 Introduction to Computer Science Loops. Instructions Pseudocode Assign values to variables using basic arithmetic operations x = 3 y = x/10 z =
Additional control structures. The if-else statement The if-else statement chooses which of two statements to execute The if-else statement has the form:
1 9/24/07CS150 Introduction to Computer Science 1 Relational Operators and the If Statement.
Flowcharts Remember that a solution to a problem is called an algorithm. Algorithms are often a series of steps required to solve the problem. A flowchart.
School of Computing Science CMT1000 Ed Currie © Middlesex University 1 CMT1000: Introduction to Programming Ed Currie Lecture 5B: Branch Statements - Making.
CIS101 Introduction to Computing Week 11. Agenda Your questions Copy and Paste Assignment Practice Test JavaScript: Functions and Selection Lesson 06,
If-else 03/13/15. Program 6 Due 4/3/14 See the 115 website.
1 CS150 Introduction to Computer Science 1 Relational Operators and the If Statement 9/22/08.
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: Control Structures: Selection
Administrative MUST GO TO CORRECT LAB SECTION! Homework due 11:59pm on Tuesday. 25 points off if late (up to 24 hours) Cannot submit after 11:59pm on Wednesday.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 9P. 1Winter Quarter Switch Case Structures.
19/5/2015CS150 Introduction to Computer Science 1 Announcements  1st Assignment due next Monday, Sep 15, 2003  1st Exam next Friday, Sep 19, 2003  1st.
Decisions – Chapter 3 IPC144 Week 2. IPC144 Introduction to Programming Using C Week 2 – Lesson 2 (Pages 12 to 18 in IPC144 Textbook)
1 If statement and relational operators –, >=, ==, != Finding min/max of 2 numbers Finding the min of 3 numbers Forming Complex relational expressions.
Chapter 02 (Part III) Introduction to C++ Programming.
Flow of Control Part 1: Selection
Logic Disjunction A disjunction is a compound statement formed by combining two simple sentences using the word “OR”. A disjunction is true when at.
Logic Our programs will have to make decisions on what to do next –we refer to the decision making aspect as logic Logic goes beyond simple if and if-else.
PROBLEM SOLVING & ALGORITHMS CHAPTER 5: CONTROL STRUCTURES - SELECTION.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 21, 2005 Lecture Number: 10.
Making Decisions (True or False) Relational Operators >greater than =greater than or equal to
Logic Our programs will have to make decisions in terms of what to do next –we refer to the decision making aspect as logic Logic goes beyond simple if.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 5: Introduction to C: More Control Flow.
Logic Our programs will have to make decisions on what to do next –we refer to the decision making aspect as logic Logic goes beyond simple if and if-else.
Chapter 7 Selection Dept of Computer Engineering Khon Kaen University.
CS161 Topic #16 1 Today in CS161 Lecture #16 Prepare for the Final Reviewing all Topics this term Variables If Statements Loops (do while, while, for)
COMP 110: Spring Announcements Lab 1 was due at noon Lab 2 on Friday (Bring Laptops) Assignment 1 is online TA Office hours online 30-min quiz at.
Chapter 4 Control Structures I. Chapter Objectives Learn about control structures Examine relational and logical operators Explore how to form and evaluate.
1 CS161 Introduction to Computer Science Topic #8.
Variables and Expressions CMSC 201. Today we start Python! Two ways to use python: You can write a program, as a series of instructions in a file, and.
Multiway Branching 03/20/15. Program 6 Due 4/3/14 See the 115 website.
EGR 115 Introduction to Computing for Engineers Branching & Program Design – Part 3 Friday 03 Oct 2014 EGR 115 Introduction to Computing for Engineers.
These Guys? Wait, What? Really?  Branching is a fundamental part of programming  It means taking an action based on decision  The decision is dependent.
Flow of Control: Loops Module 4. Objectives Design a loop Use while, do, and for in a program Use the for-each with enumerations Use assertion checks.
COMP Loop Statements Yi Hong May 21, 2015.
Beginning C For Engineers Fall 2005 Lecture 3: While loops, For loops, Nested loops, and Multiple Selection Section 2 – 9/14/05 Section 4 – 9/15/05 Bettina.
C Language 1 Program Looping. C Language2 Topics Program looping Program looping Relational operators / expressions Relational operators / expressions.
CSE202: Lecture 5The Ohio State University1 Selection Structures.
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
Conditional Statements A conditional statement lets us choose which statement will be executed next Conditional statements give us the power to make basic.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Basic concepts of C++ Presented by Prof. Satyajit De
CS0007: Introduction to Computer Programming
INC 161 , CPE 100 Computer Programming
Decisions Chapter 4.
Chapter 4 (Conditional Statements)
EKT150 INTRODUCTION TO COMPUTER PROGRAMMING
Chapter 4 LOOPS © Bobby Hoggard, Department of Computer Science, East Carolina University / These slides may not be used or duplicated without permission.
TOPIC 4: REPETITION CONTROL STRUCTURE
Loops A portion of a program that repeats a statement or a group of statements is called a loop. The statement or group of statements to be repeated is.
Computers & Programming Languages
Bools & Ifs.
Visual Basic – Decision Statements
Selection Statements.
SELECTIONS STATEMENTS
Flowcharts and Pseudo Code
Chapter 4: Boolean Expressions, Making Decisions, and Disk Input and Output Prof. Salim Arfaoui.
More Loops Topics Relational Operators Logical Operators for Loops.
Module 3 Selection Structures 6/25/2019 CSE 1321 Module 3.
Switch Case Structures
Presentation transcript:

Selection 03/7/15

Programs Get help if you are not getting homework. –It's 40% of your grade

Selection Lets us make decisions in a program. – e.g. "Shall I buy this jacket?" If statement is used for selection. if(price < 100.0)‏ printf(“Buy the jacket.\n”);

Relational Expression Is either true or false. Used in if expression. –(price < 100.0)‏

Relational Operators CMath<> === <=≤ >=≥ !=≠

Examples int n = 5, p = 10; //true or false? (n < 5)‏ (p >= 10)‏ (p + n <= 12)‏

Character Comparison ‘A’ < ‘B’ < ‘C’ … < ‘Z’ ‘a’< ‘b’ < ‘c’ … < ‘z’ ‘0’ < ‘1’ < ‘2’ … < ‘9’ True or False? ‘a’ > ‘w’ ‘W’ < ‘Z’ ‘Y’ == ‘y ‘8’ >= ‘4’

Participation int x = 4, y = 8; //true or false? (x != y) (x + 4 == y) (24 > x * y) 'b' == 'B' 'e' > 'i'

Write Relational Expressions For: ➲ The high today is below 70 ➲ The average on an exam was 88 ➲ The month, given as an integer, is in the 1 st quarter of the year.

if statement Simple if in C Syntax: (indentation is good style) if(expression)‏ statement; Statement executed only when expression is true. No ";" on the if line. ( ) are required.

if statement Example: int age = 19; if(age >= 18)‏ printf(“Vote on November 4th\n”);

if Example Program gasif.c

Compound Statement When you want to do more than one statement when the condition is true. Inside { } if (expression)‏ { statement 1; statement 2;. statement n; }

Example freeShip.c

Write a Program Write a program let the user input the time it takes to drive from their home to a prospective job. If the driving time is more than 30 min., output “too far”. No matter the outcome, output “Good Luck!”. Algorithm? Started in jobDrive.c

Programming Style Indentation –Indent statements between { } Spacing –Use blank lines to break up the program into logical parts. Comments –Name, Date, Description of program Meaningful identifiers –“time” instead of “x” I will put some comments in jobDrive.c

Questions ➲ Give an example of a relation operator in C. ➲ Is indentation required in the syntax of an if statement? ➲ What is wrong with this piece of a C program? scanf("%d", count); if count >= 5 ; printf("Basketball team.\n");

Participation ➲ Write a program to ask the user for the date. If 15 is input output a message that says, "Beware of the Ides of March." Otherwise output "March Winds."