Decision Structures - PowerPoint PPT Presentation

1 / 19
About This Presentation
Title:

Decision Structures

Description:

You have a program where people enter ... It's rare to be born on 02/29, so output a message to all those people saying, 'Congrats! You were born on Leap Day! ... – PowerPoint PPT presentation

Number of Views:40
Avg rating:3.0/5.0
Slides: 20
Provided by: horiz3
Category:

less

Transcript and Presenter's Notes

Title: Decision Structures


1
Decision Structures
  • How to make your algorithm follow more than just
    one path

2
If
3
IF Flowchart
Decision
T
F
Do if true
Do no matter what
4
IF Pseudocode
  • If TextBox shows the right answer then
  • Output Correct!
  • Disable button
  • End if

5
If Problem
  • You have a program where people enter info about
    themselves, including their birthday in the
    format mm/dd.
  • Its rare to be born on 02/29, so output a
    message to all those people saying, Congrats!
    You were born on Leap Day!
  • After that the program should continue as normal
    and ask for their occupation.

6
Flowchart
7
Pseudocode
  • If

8
If-Else
9
If-Else
Decision
T
F
Do ELSE steps
Do IF steps
Continue in either case
10
IF-ELSE Pseudocode
  • If TextBox shows the right answer then
  • Output Correct!
  • Disable button
  • Else
  • Output Sorry, try again!
  • End if

11
If-Else Problem
  • You want to get an average score for the class
    (AverageScore), so you need to divide TotalScores
    by NumberStudents, but you cant divide by zero
    or the program will crash.
  • Check if the user has entered zero if so, dont
    do the calculation and output a message stating
    the error.
  • If there is no zero problem, do the calculation
    and output the answer.
  • After either process, increment Counter by one

12
Flowchart
13
Pseudocode
  • If

14
While Loop
15
While Loop
Change looping variable
Decision
T
Stuff you want to repeat
F
Continues after decision is false
16
WHILE Pseudocode
  • Counter 1
  • While counter is less than 4
  • If TextBox.Text is correct then
  • Output Correct!
  • Disable button
  • Else
  • Output Sorry, try again.
  • End if
  • End while
  • Output Sorry, youve used up your guesses.
  • Disable button

17
While Problem
  • You want to add all the numbers between zero and
    the positive number the user enters (Number)
  • After the loop is finished, output Sum

18
Flowchart
19
Pseudocode
  • While

20
Repeat (loop of uncertain length)
T
Decision
Repeats until decision is false
F
  • Decision made at END of loop

Continues after decision is false
21
Example REPEAT Structure
  • Repeat
  • Output Sorry, try again!
  • Until TextBox shows right answer
  • Output Correct!
  • (continually tests the TextBox needs no enter
    button code attached to TextBox)

22
For-To (loop of certain length)
Change counter by one
Decision defines counter
This gets repeated
T
F
Continues after counter finished
23
Example FOR-TO Structure
  • COUNTER 1
  • For COUNTER 1 to 5
  • Allow input (TextBox)
  • Allow test (attached to Button)
  • If-Else decision structure
  • Add one to COUNTER
  • End for
  • Output Sorry, you used up your 5 guesses
  • Disable button
  • (attached to main form each time the button is
    pressed, the counter goes up)
Write a Comment
User Comments (0)
About PowerShow.com