Ifs and Logic - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

Ifs and Logic

Description:

Or ... Is it True or False. Lackey - Many IFs cpp2cppmanyifs. 2. Comparison operators ... note: true is the integer value 1 and false is the integer value 0 ... – PowerPoint PPT presentation

Number of Views:116
Avg rating:3.0/5.0
Slides: 13
Provided by: EdwardDon8
Category:
Tags: false | fount | ifs | logic | or | single1 | true | value1

less

Transcript and Presenter's Notes

Title: Ifs and Logic


1
Ifs and Logic
  • Or
  • Is it True or False.

2
Comparison operators
  • A gt B is false (value of 0)
  • D gt A is true (value of 1)
  • 4 4 is true
  • 5 lt 3 is false (value of 0)
  • a ! A is true
  • note true is the integer value 1 and false is
    the integer value 0

3
Logical operators
  • is AND
  • is OR
  • are valuated before unless parentheses are
    used.

4
DeMorgans Law
  • NOT (A AND B)(NOT A) OR (NOT B)
  • NOT (A OR B)(NOT A) AND (NOT B)
  • A NOT (NOT A)
  • A AND B NOT( (NOT A) OR NOT(B))

5
Many forms of IF
  • if (condition) single_statement
  • if (condition)
    single1 else
    single2
  • if (condition)
    many statements else
    many other statements

6
Good practice
  • A block of code is fount between and
  • Good practice is to code if else with blocks
  • if (condition)
    many statements else
    many other statements
  • This is true even if a block is empty.

7
else if
  • if (condition)
    single1 else if (condition2)
    single2 else if (condition3) single
    3 else single4

8
Flow Charts
  • Conventional
  • Nassi-Schneiderman

9
switch
  • switch(k)
  • case 1
  • cout ltlt Hiltltendl
  • break
  • case 4
  • cout ltlt Good-byltlt endl
  • break
  • default
  • cout ltltTry Againltltendl

10
switch components
  • switch (expression)
  • case value1
  • many_statements
  • break
  • case values 2
  • many_ statements

11
  • break
  • default
  • many statements

12
To Do
  • Modify the average of 3 exams to display a letter
    grade of A, B, C, D or F if the average is 90 or
    better 80 or better etc.
  • Write a program that will input an integer and
    display odd if it is odd and even if it is
    even. This is a good program to use the
    division.
Write a Comment
User Comments (0)
About PowerShow.com