Module 3 SELECTION STRUCTURES 2/15/19 CSE 1321 MODULE 3 1

Similar documents
Control Structures in Java if-else and switch

Chapter 3. Selections

Control Structures in Java if-else and switch

Full file at

Control Structures. Lecture 4 COP 3014 Fall September 18, 2017

COMP-202: Foundations of Programming. Lecture 3: Boolean, Mathematical Expressions, and Flow Control Sandeep Manjanna, Summer 2015

Boolean Expressions. So, for example, here are the results of several simple Boolean expressions:

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Fall 2016 Howard Rosenthal

COMP 202 Java in one week

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal

Algorithms and Conditionals

BRANCHING if-else statements

CONTENTS: Compilation Data and Expressions COMP 202. More on Chapter 2

Lecture Set 2: Starting Java

Programming with Java

Lecture Set 2: Starting Java

Conditional Programming

JAVA OPERATORS GENERAL

cis20.1 design and implementation of software applications I fall 2007 lecture # I.2 topics: introduction to java, part 1

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

School of Computer Science CPS109 Course Notes 5 Alexander Ferworn Updated Fall 15

Topics. Chapter 5. Equality Operators

Lesson 7 Part 2 Flags

COMP Primitive and Class Types. Yi Hong May 14, 2015

Introduction to Computer Science Unit 2. Notes

CSE Module 1. A Programming Primer 1/23/19 CSE 1321 MODULE 1 1

Key Concept: all programs can be broken down to a combination of one of the six instructions Assignment Statements can create variables to represent

Review Chapters 1 to 4. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

Operators in java Operator operands.

Java Bytecode (binary file)

Introduction to Java & Fundamental Data Types

Operators. Java operators are classified into three categories:

Two Types of Types. Primitive Types in Java. Using Primitive Variables. Class #07: Java Primitives. Integer types.

Selection Statements and operators

Computer Science II Lecture 1 Introduction and Background

In Java, data type boolean is used to represent Boolean data. Each boolean constant or variable can contain one of two values: true or false.

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;

AP Computer Science Unit 1. Programs

Logical Operators and switch

Interpreted vs Compiled. Java Compile. Classes, Objects, and Methods. Hello World 10/6/2016. Python Interpreted. Java Compiled

Visual C# Instructor s Manual Table of Contents

Chapter 3. More Flow of Control. Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Java I/O and Control Structures

Administration. Conditional Statements. Agenda. Syntax. Flow of control. Lab 2 due now on floppy Lab 3 due tomorrow via FTP

Chapter 3: Operators, Expressions and Type Conversion

CT 229 Java Syntax Continued

PROGRAMMING FUNDAMENTALS

Handout 4 Conditionals. Boolean Expressions.

QUIZ: What value is stored in a after this

CS 231 Data Structures and Algorithms Fall Event Based Programming Lecture 06 - September 17, Prof. Zadia Codabux

CS11 Java. Fall Lecture 1

Darrell Bethea May 25, 2011

Motivating Examples (1.1) Selections. Motivating Examples (1.2) Learning Outcomes. EECS1022: Programming for Mobile Computing Winter 2018

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp

More Things We Can Do With It! Overview. Circle Calculations. πr 2. π = More operators and expression types More statements

Lecture Set 4: More About Methods and More About Operators

Full file at

Chapter 2. Elementary Programming

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

CS 106 Introduction to Computer Science I

Variables and data types

1.00 Lecture 4. Promotion

CMPT 125: Lecture 4 Conditionals and Loops

Prof. Navrati Saxena TA: Rochak Sachan

Computer Components. Software{ User Programs. Operating System. Hardware

CSE 115. Introduction to Computer Science I

Java I/O and Control Structures Algorithms in everyday life

Conditionals and Loops

Lecture 3 Tao Wang 1

Objectives. Chapter 4: Control Structures I (Selection) Objectives (cont d.) Control Structures. Control Structures (cont d.) Relational Operators

In this chapter, you will:

COMP 202 Java in one week

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics

Course Outline. Introduction to java

AP CS Unit 3: Control Structures Notes

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

Computer Components. Software{ User Programs. Operating System. Hardware

COMP-202: Foundations of Programming. Lecture 2: Variables, and Data Types Sandeep Manjanna, Summer 2015

Flow of Control. Flow of control The order in which statements are executed. Transfer of control

V2 2/4/ Ch Programming in C. Flow of Control. Flow of Control. Flow of control The order in which statements are executed

CS313D: ADVANCED PROGRAMMING LANGUAGE

Lecture Notes. System.out.println( Circle radius: + radius + area: + area); radius radius area area value

Chapter 4: Control Structures I (Selection) Objectives. Objectives (cont d.) Control Structures. Control Structures (cont d.

cs1114 REVIEW of details test closed laptop period

Lecture Programming in C++ PART 1. By Assistant Professor Dr. Ali Kattan

Selection Statements and operators

Selections. EECS1021: Object Oriented Programming: from Sensors to Actuators Winter 2019 CHEN-WEI WANG

CS 106 Introduction to Computer Science I

DM550 Introduction to Programming part 2. Jan Baumbach.

Basics of Java Programming

Fundamentals of Programming (Python) Getting Started with Programming

4 Programming Fundamentals. Introduction to Programming 1 1

Lecture Set 4: More About Methods and More About Operators

Making Decisions Chp. 5

ECE 122 Engineering Problem Solving with Java

STUDENT LESSON A12 Iterations

Chapter 2: Data and Expressions

Flow Control. So Far: Writing simple statements that get executed one after another.

Control Statements: Part 1

Transcription:

Module 3 SELECTION STRUCTURES 2/15/19 CSE 1321 MODULE 3 1

Motivation In the programs we have written thus far, statements are executed one after the other, in the order in which they appear. Programs often need more than one path of execution, however. Many algorithms require a program to execute some statements only under certain circumstances. This can be accomplished with decision structures. 2/15/19 CSE 1321 MODULE 3 2

Topics 1. Flow of Control 2. Boolean definition & Conditional Statements 3. Relational Operators 4. Logical Operators 5. Operator Precedence 6. if statements 7. if-else statements 8. if-else-if statements 9. switch statements 2/15/19 CSE 1321 MODULE 3 3

1. Flow of Control The order of statement execution is called the flow of control By default, execution is linear: one statement after another However, we can: decide whether or not to execute a particular statement execute a statement over and over, repetitively These selection (decision) statements are based on boolean expressions (or conditions) that evaluate to true or false 2/15/19 CSE 1321 MODULE 3 4

A Flow Diagram 2/15/19 CSE 1321 MODULE 3 5

2. The Boolean A Boolean resolvesto either true or false You can get Boolean values several different ways Simple Complex These Booleans will be used (later) to make decisions 2/15/19 CSE 1321 MODULE 3 6

2. Selection Statements A Selection (conditional) statement allows us to choose which statements will be executed next: if block of code executes if a Boolean expression is true. if-else will execute one block of code if the Boolean expression is true, or another if it is false. if-else-if tests a series of Boolean expressions and execute corresponding block when it finds one that is true. switch lets the value of a variable determine where the program will branch to. 2/15/19 CSE 1321 MODULE 3 7

3. Relational Operators Create a true or false using a relational operator: > greater than < less than == equals! not!= not equal >= greater than or equal <= less than or equal Note the difference between the equality operator (==) and the assignment operator (=) 2/15/19 CSE 1321 MODULE 3 8

Relational Operators Example Literal Example: 5 > 3 // true 6!= 6 // false true == (4 <=2) // false c!= b // true!false // true Variable Example: Num1 5 Num2 7 Result Num2 > Num1 // Result is now true 2/15/19 CSE 1321 MODULE 3 9

4. Logical Operators Boolean expressions can also use the following logical operators: Logical NOT Logical AND Logical OR Exclusive OR They all take Boolean operands and produce Boolean results Logical NOT is a unary operator (it operates on one operand) Logical AND and OR are binary operators (each operates on two operands) 2/15/19 CSE 1321 MODULE 3 10

Logical Operators (NOT) The logical NOT operation is also called logical negation or logical complement If some Boolean condition a is true, then NOT a is false; if a is false, then NOT a is true Logical expressions can be shown using a truth table 2/15/19 CSE 1321 MODULE 3 11

Logical Operators (AND and OR) The logical AND expression a AND b is true if both a and b are true, and false otherwise The logical OR expression a OR b is true if either a or b or is true, or both are true, and false otherwise 2/15/19 CSE 1321 MODULE 3 12

Logical Operators

Logical Operators in Boolean Expressions Expressions can form complex conditions IF (total < MAX + 5 AND NOT found) THEN Print ("Processing ") ENDIF Mathematical operators have higher precedence than the Relational and Logical operators Relational operators have higher precedence than Logical operators 2/15/19 CSE 1321 MODULE 3 14

Boolean Expressions Specific expressions can be evaluated using truth tables Given X = total < MAX + 5 AND NOT found What is the values of X?

5. Order of Precedence of Arithmetic, Comparison, and Logical Operators Source: http://www.bouraspage.com/repository/algorithmic-thinking/what-is-the-order-of-precedence-of-arithmetic-comparison-and-logical-operators 2/15/19 CSE 1321 MODULE 3 16

5. Order of Precedence of Arithmetic, Comparison, and Logical Operators Source: http://www.bouraspage.com/repository/algorithmic-thinking/what-is-the-order-of-precedence-of-arithmetic-comparison-and-logical-operators 2/15/19 CSE 1321 MODULE 3 17

Operator Precedence Applying operator precedence and associativity rule to the expression: 3 + 4 * 4 > 5 * (4 + 3) - 1 (1) Inside parentheses first (2) Multiplications (3) Addition (4) Subtraction (5) Greater than The expression resolves to FALSE 2/15/19 CSE 1321 MODULE 3 18

Notes on Indentation In Java and C# Makes no difference, but crucial for readability and debugging. Code inside the IF statement is indented and should also be enclosed in curly braces { }. In Python Indentation matters in Python! Leading whitespace at the beginning of a logical line is used to determine the grouping of statements. No curly braces required. Note! Code samples in this slide show may have to be re-formatted if copied and pasted. 2/15/19 CSE 1321 MODULE 3 19

6. Logic of an IF Statement 2/15/19 CSE 1321 MODULE 3 20

Now Let s Do Something! Using the IF statement, we can decide whether or not to execute some code Has format: IF (condition) THEN // all the code that s here will only execute // IF and only IF the condition above is true ENDIF 2/15/19 CSE 1321 MODULE 3 21

Problem Statement Write a program to convert user input of Celsius temperature to Fahrenheit. Display the converted temperature to the user. Issue a heat warning IF temperature is over 90 degrees Fahrenheit. 2/15/19 CSE 1321 MODULE 3 22

Pseudocode - IF Statement MAIN Fahrenheit 0, Celsius 0 PRINT Enter Celsius temperature: READ user input Celsius user input Fahrenheit 9.0 / 5.0 * Celsius + 32 PRINT Fahrenheit IF (Fahrenheit > = 90) THEN PRINT heat warning ENDIF END MAIN 2/15/19 CSE 1321 MODULE 3 23

Java Example - if Statement import java.util.scanner; public class CelsiusToFahrenheit { public static void main (String[] args) { double celsius= 0.0, fahrenheit = 0.0; Scanner scan = new Scanner (System.in); System.out.print ( What is the Celsius temperature? "); celsius = scan.nextdouble(); fahrenheit = 9.0 / 5.0 * celsius + 32; System.out.println ( The temperature is " + fahrenheit + degrees Fahrenheit ); if (fahrenheit >= 90) { System.out.println( It is really hot out there! ); } } } 2/15/19 CSE 1321 MODULE 3 24

C# Example - if Statement using System; class Program { public static void Main(string[] args) { double celsius = 0.0, fahrenheit = 0.0; Console.Write("What is the Celsius temperature? "); celsius = Convert.ToDouble(Console.ReadLine()); fahrenheit = 9.0 / 5.0 * celsius + 32; Console.WriteLine("The temperature is " + fahrenheit + " degrees Fahrenheit"); if (fahrenheit >= 90) { Console.WriteLine("It is really hot out there!"); } } } 2/15/19 CSE 1321 MODULE 3 25

Python Example if Statement def main(): celsius = float(input("what is the Celsius temperature? ")) fahrenheit = 9.0 / 5.0 * celsius + 32.0 print ("The temperature is", fahrenheit, "degrees Fahrenheit.") if (fahrenheit >= 90): print ("It's really hot out there!") main() # From: mcsp.wartburg.edu/zelle/python/ppics1/slides/chapter07.ppt 2/15/19 CSE 1321 MODULE 3 26

7. Structure of an IF-ELSE Statement IF has a counterpart the ELSE statement Has format: IF (condition) THEN statementblock that executes if condition is true ELSE statementblock that executes if condition is false ENDIF IF the condition is true, statementblock1 is executed; IF the condition is false, statementblock2 is executed Notice there is no condition after the ELSE statement. One or the other will be executed, but not both 2/15/19 CSE 1321 MODULE 3 27

7. Logic of an IF-ELSE statement 2/15/19 CSE 1321 MODULE 3 28

Problem Redefined Original Problem Statement: Write a program to convert user input of Celsius temperature to Fahrenheit. Display the converted temperature to the user. Issue a heat warning IF temperature is over 90 degrees Fahrenheit. Add: IF the temperature is not that high, output a message to the user. 2/15/19 CSE 1321 MODULE 3 29

Pseudocode IF-ELSE Statement MAIN Fahrenheit 0, Celsius 0 PRINT Enter Celsius temperature: READ user input Celsius user input Fahrenheit 9.0 / 5.0 * Celsius + 32 PRINT Fahrenheit IF (Fahrenheit > = 90) THEN PRINT heat warning ELSE ENDIF END MAIN PRINT there is no extreme heat 2/15/19 CSE 1321 MODULE 3 30

Java Example if-else (code snippet) double celsius= 0.0, fahrenheit = 0.0; Scanner scan = new Scanner (System.in); System.out.print ( What is the Celsius temperature? "); celsius = scan.nextdouble(); fahrenheit = 9.0 / 5.0 * celsius + 32; System.out.println ( The temperature is " + fahrenheit + degrees Fahrenheit ); if(fahrenheit >= 90) { System.out.println( It is really hot out there! ); } else { System.out.println( There is no extreme heat today. ); } 2/15/19 CSE 1321 MODULE 3 31

C# Example if-else (Code Snippet) double celsius = 0.0, fahrenheit = 0.0; Console.Write("What is the Celsius temperature? "); celsius = Convert.ToDouble(Console.ReadLine()); fahrenheit = 9.0 / 5.0 * celsius + 32; Console.WriteLine("The temperature is " + fahrenheit + " degrees Fahrenheit"); if (fahrenheit >= 90) { Console.WriteLine("It is really hot out there, be careful!"); } else { Console.WriteLine( There is no extreme heat today. ); } 2/15/19 CSE 1321 MODULE 3 32

Python if-else example celsius = float(input("what is the Celsius temperature? ")) fahrenheit = 9.0 / 5.0 * Celsius + 32 print ("The temperature is", fahrenheit, "degrees Fahrenheit. ) if (fahrenheit >= 90): print ( It's really hot out there, be careful! ) else: print ( There is no extreme heat today. ) 2/15/19 CSE 1321 MODULE 3 33

8. Structure of an IF-ELSE-IF Selectingonefrom many As soon as one is true, the rest are not considered Has format: IF (condition) THEN //statementblock that executes if the above boolean is true ELSE IF (condition) THEN //statementblock that executes if the above boolean is true ELSE IF (condition) THEN //statementblock that executes if the above boolean is true ELSE //statementblock that executes if the nothing matched above ENDIF Note: only one set of statements will ever execute. Trailing else is optional 2/15/19 CSE 1321 MODULE 3 34

8. Logic of an IF-ELSE-IF 2/15/19 CSE 1321 MODULE 3 35

Problem Redefined Original Problem Statement: Write a program to convert user input of Celsius temperature to Fahrenheit. Display the converted temperature to the user. Issue a heat warning if temperature is over 90 degrees Fahrenheit. Add: two additional messages to recommend an action based on temperature, and a trailing else. 2/15/19 CSE 1321 MODULE 3 36

Pseudocode IF-ELSE-IF MAIN Fahrenheit 0, Celsius 0 PRINT Enter Celsius temperature: READ user input Celsius user input Fahrenheit 9.0 / 5.0 * Celsius + 32 PRINT Fahrenheit IF (Fahrenheit > = 90) THEN PRINT heat warning ELSE IF (Fahrenheit >= 80) THEN PRINT it is warm, but there is no extreme heat ELSE IF (Fahrenheit >= 70) THEN PRINT the temperature is pleasant and suggest a picnic ELSE PRINT a suggestion to take a jacket END IF END MAIN 2/15/19 CSE 1321 MODULE 3 37

Java Example if-else-if double celsius= 0.0, fahrenheit = 0.0; Scanner scan = new Scanner (System.in); System.out.print ( What is the Celsius temperature? "); celsius = scan.nextdouble(); fahrenheit = 9.0 / 5.0 * celsius + 32; System.out.println ( The temperature is " + fahrenheit + degrees Fahrenheit ); if (fahrenheit >= 90){ System.out.println( It is really hot out there! ); } else if (fahrenheit >= 80) { System.out.println( It is very warm... ); } // CONTINUED ON NEXT SLIDE 2/15/19 CSE 1321 MODULE 3 38

Java Example if-else-if (con t) else if (fahrenheit >= 70) { System.out.println( It is very pleasant today! ) } else { System.out.println( It is cool today. Take a jacket. ); } 2/15/19 CSE 1321 MODULE 3 39

C# Example if-else-if double celsius = 0.0, fahrenheit = 0.0; Console.Write("What is the Celsius temperature? "); celsius = Convert.ToDouble(Console.ReadLine()); fahrenheit = 9.0 / 5.0 * celsius + 32; Console.WriteLine("The temperature is " + fahrenheit + "degrees Fahrenheit"); if(fahrenheit >= 90){ Console.WriteLine( It is really hot! ); } else if (fahrenheit >= 80){ Console.WriteLine( It is very warm! ); } else if (fahrenheit >= 70){ Console.WriteLine( It is very pleasant! ) } else { Console.WriteLine( It is cool today ); } 2/15/19 CSE 1321 MODULE 3 40

Python if-else-if example celsius = float(input("what is the Celsius temperature? ")) fahrenheit = 9.0 / 5.0 * celsius + 32 print ("The temperature is", fahrenheit, " degrees Fahrenheit.") if (fahrenheit >= 90): print ("It's really hot out there, be careful!") elif (fahrenheit >= 80): print ("It is warm, but there is no extreme heat today.") elif (fahrenheit >= 70): print ("It is very pleasant today. You should pack a picnic!") else: print ("It is cool today. You should take a jacket.") 2/15/19 CSE 1321 MODULE 3 41

9. The switch Statement The switch statement provides another way to decide which statement to execute next The switch statement evaluates an expression, then attempts to match the result to one of several possible cases (cases) Each case contains a value and a list of statements The flow of control transfers to statement associated with the first case value that matches 2/15/19 CSE 1321 MODULE 3 42

9. Structure of a switch The general syntax of a switch statement is: SWITCH variable BEGIN CASE 1: statementblock break // SUPER IMPORTANT BREAKS! CASE 2: statementblock break // If we don t include breaks, it goes to next condition CASE 3: statementblock break CASE... DEFAULT: statementblock END 2/15/19 CSE 1321 MODULE 3 43

7. Logic of switch statement 2/15/19 CSE 1321 MODULE 3 44

break Statement Often a break statement is used as the last statement in each case's statement list A break statement causes control to transfer to the end of the switch statement If a break statement is not used, the flow of control will continue into the next case Sometimes this may be appropriate, but often not 2/15/19 CSE 1321 MODULE 3 45

Default Case A switch statement can have an optional default case The default case has no associated value and simply uses the reserved word default If the default case is present, control will transfer to the default case if no other case value matches If there is no default case, and no other value matches, control falls through to the statement after the switch statement 2/15/19 CSE 1321 MODULE 3 46

Switch Statement Expression The expression of a switch statement must result in an integer type (byte, short, int, long) or a char type. It cannot be a boolean value or a floating point value (float or double) You cannot perform relational checks with a switch statement In Java and C#, you can also switch on a string In Python, it s a bit contrived! 2/15/19 CSE 1321 MODULE 3 47

Problem Redefined Original Problem Statement: Write a program to convert user input of Celsius temperature to Fahrenheit. Display the converted temperature to the user. Add: Using the Fahrenheit temperature and division, determine the conditions outside (i.e., in the 100 s, 90 s, etc.). Use a switch statement to recommend user action based on the result. If it is in the 60 s or below, suggest the user take a jacket. 2/15/19 CSE 1321 MODULE 3 48

Pseudocode switch Statement // Read user input like before conditions compute using Fahrenheit variable / 10 SWITCH variable CASE 10 : PRINT stay inside, BREAK CASE 9 : PRINT be careful due to heat, BREAK CASE 8 : PRINT it is hot, but not extreme, BREAK CASE 7 : PRINT pack a picnic, BREAK DEFAULT : PRINT take a jacket, BREAK ENDCASE 2/15/19 CSE 1321 MODULE 3 49

Java switch Example int condition = (int)fahrenheit / 10; System.out.println("It is in the " + condition + 0's."); switch (condition) { case 10: System.out.println("Stay inside!"); break; case 9: System.out.println("It is really hot out there!"); break; case 8: System.out.println("It s warm, but no extreme heat!"); break; case 7: System.out.println("It is very pleasant today!"); break; default: System.out.println("Take a jacket!"); break; } 2/15/19 CSE 1321 MODULE 3 50

C# switch Example int conditions = (int)fahrenheit / 10; Console.WriteLine("It is in the " + conditions + "0's."); switch (conditions) { case 10: Console.WriteLine("It s hot! Stay inside!"); break; case 9: Console.WriteLine("It is really hot out there!"); break; case 8: Console.WriteLine("It is warm, but no extreme heat!"); break; case 7: Console.WriteLine("It is very pleasant today!"); break; default: Console.WriteLine("Take a jacket!"); break; } 2/15/19 CSE 1321 MODULE 3 51

Note: Python does not provide a switch statement, but we can implement with dictionary mapping. At this point, you may or may not be ready to try this. Remember you can accomplish the same tasks with if/elif Python switch example def case_10_handler(): print('it is too hot to go outside today. Stay inside!') def case_9_handler(): print('it is really hot out there, be careful!') def case_8_handler(): print('it is very warm, but no extreme heat today!') def case_7_handler(): print('it is very pleasant today. You should pack a picnic!') def default_handler(): print('it is cool today. You should take a jacket.') def switch_function(switch): handler = { 10: case_10_handler, 9: case_9_handler, 8: case_8_handler, 7: case_7_handler, } return handler.get(switch)() #extra parentheses for executing function #Continued on next slide 2/15/19 CSE 1321 MODULE 3 52

Python switch example #Continued from slide 44 def main(): celsius = float(input("what is the Celsius temperature? ")) fahrenheit = 9.0 / 5.0 * celsius + 32 conditions = int(fahrenheit/10) print("it is in the ", conditions,"0's.") switch_function(conditions) if name == " main ": main() 2/15/19 CSE 1321 MODULE 3 53

In-class Problem Write a pseudocode program that reads in all grades from CSE 1321 lecture (quizzes and tests) and calculates a final grade. Then, based on that final grade, the program prints out the correct letter grade the student earned (e.g. 90-100 is an A, 80-89 is a B, and so on) 2/15/19 CSE 1321 MODULE 3 54

BEGIN MAIN CREATE/READ studentname // Note: we use a shortcut for this example only CREATE/READ quiz grades 1-12 CREATE/READ test grades 1-4 CREATE lettergrade CREATE quizavg = (quiz1 + quiz2 +...quiz12)/12 CREATE testavg = (test1 + test2 + test3 + test4) CREATE finalgrade = testavg * 0.80 + quizavg * 0.20 SWITCH (finalgrade) CASE 90 to 100 lettergrade = A, BREAK CASE 80 to 89 lettergrade = B, BREAK CASE 70 to 79 lettergrade = C, BREAK CASE 60 to 69 lettergrade = D, BREAK CASE default lettergrade = F, BREAK END SWITCH Print studentname, finalgrade, lettergrade END MAIN 2/15/19 CSE 1321 MODULE 3 55

Summary Boolean values can be generated several ways Use the if statement to decide which path to take Use the else to take the alternate path The if-else-if statements allow for selecting one from many Use the switch statement to allow a variable or expression to determine program path 2/15/19 CSE 1321 MODULE 3 56