Title: Structured thinking
1Structured thinking
2Contents
3Structure diagram
Morningwhile has gold in mouthd
4Sequence (order in time)
Sequence
Sequence parts
5Structure diagram
Morningwhile has gold in mouthd
Division
Time
6Selection
Selection
Selection parts
7Structure diagram
Morningwhile has gold in mouthd
Division
Time
8Iteration (repetition)
Iteration
As long as youre thirsty
Iteration part
9Structure diagram
Morningwhile has gold in mouthd
Division
Time
10Flow chart
11Summary
- A problem can be divided into a number of smaller
problems. - When programming, it can sometimes be difficult
to know where to start.This is where you use a
structure diagram.
12The endpart 1
13Program structure
- Examples
- Rules
- More examples
14Crossing
Imagine driving in car B, just behind another car
A. You come to a crossing. How will you know
which direction it will chose?
Car A has to make a selection
B
15Crossing a selection of directions
How can you see in which direction the car in
front of you will choose?
Crossing
16Marriage - a selection?
not JSP
17Selectionparts
- A selection must contain at least two selection
components. If It only contains one there is no
selection.
Young mans future choice
18Al Bundy?
It is however possible to leave a selection
component empty.
Young mans future choice
19Example of an iteration
Label
20Rules of Christmas
Santa Claus X-mas day
not JSP
21Santa changed his mind
- Parts connected to the same component must be of
similar type
Santa Claus X-mas day
22Paint house - an iteration
Paint
House
not JSP
23Now you can begin to paint
- An iteration can only contain one repeated
component
Paint
House
24Example of JSP
25Program structure
Transfering the problem into code
- Split the problem into smaller problems
- Make a structure of the problems (indata/outdata)
- Write down an operationlist and the conditions
?
26What is an operation?
- An operation describes WHAT to do with all the
data that exist in the structure.
- An operation can for instance read information,
calculate, sort, seek, print, etc..
27Example Construct a programstructure to a
program that calculates and prints the area of a
circle
Operationlist - what do we need?
Program
We realize there is three important operations we
need to complete this task.
Radius and Area
- First, we need to put in (input) the radius of
the circle
- Second, calculate the area
- Third, print (output) the answer
28And..
29Operationlist
Operationlist
1. Read length of rectangle
2. Read width of rectangle
3. Read selection (area/circumference)
4. Calculate area of rectangle
5. Print area of rectangle
6. Calculate circumference
7. Print circumference of rectangle
Area or circumf.
Area
Cirumf.
A structure to a program that calculates the area
or the circumference to a rectangle
30Program structure
Operationlist 1. Print headline of table 2. Input
value of x 3. Print x value 4. Calculate value if
y 5. Print y value Conditionlist (C 1) Until x
100
Program
Headline of
Table
table
Until x 100
Pair of
numbers
- A conditionlist contains all the conditions used
in the structure
31Program structure
Transfering the problem into code
- Split the problem into smaller problems
- Make a structure of the problems (indata/outdata)
- Write an operationslist and the conditions
?
32What is pseudocode?
- Pseudocode is a combination between
- ordinary language and real programcode
- The pseudocode includes the sequences,
- selections, iterations, conditions and operations
- placed in the structurediagram
- Pseudocode can be used to simplify the
- structured problem before it becomes
- real programcode
33Milk the cow - Pseudocode
Peasant needs
money
34Milk the cow - Pseudocode
Peasant needs
money
Operationlist
Milk the
cow
1. Input peasant_tired value 2. Read selection
(hand/machine) 3. Input milk value 4.
Squeeze 5. Read milk value 6. Squeeze 7. Read
milk value
Conditionlist
1. If peasant_tired yes (sel bm) 2. While milk
exist 3. While milk exist
35Milk the cow - Pseudocode
Peasant needs
money
IFneighbour_home yes
ELSE
By hand
WHILE milk exist
Squeeze
36Milk the cow - Pseudocode
Peasant needs
money
Sell milk
If neighbour _home
37Milk the cow - Pseudocode
Peasant needs
money
38Pseudocode
PEASANT NEEDS MONEY Input peasant value IF
peasant_tired yes milk with machine ELSE
milk by hand ENDIF Input milk value
WHILE milk exist Squeeze Read milk value
ENDWHILE Input neighbour_home IF
neighbour_home yes sell milk to neighbours
ELSE sell milk in village ENDIF Input
money value WHILE money exist Buy clothes
for wife Read money value ENDWHILE
Operationlist
1. Input peasant value 2. Read selection
(hand/machine) 3. Input milk value 4.
Squeeze 5. Read milk value 6. Squeeze 7. Read
milk value
8. Input neighbour_home value 9. Read
selection(neighbour/village) 10. Sell to
neighbours 11. Sell to village 12. Input money
value
13. Buy clothes 14. Read money value
Conditionlist
1. If peasant_tired yes (sel bm) 2. While milk
exist 3. If neighbour_home yes 4. While money
exist
39Pseudocode
PEASANT NEEDS MONEY Input peasant value IF
peasant_tired yes milk with machine ELSE
milk by hand ENDIF Input milk value
WHILE milk exist Squeeze Read milk value
ENDWHILE Input neighbour_home IF
neighbour_home yes sell milk to neighbours
ELSE sell milk in village ENDIF Input
money value WHILE money exist Buy clothes
for wife Read money value ENDWHILE
Operationlist
1. Input peasant value 2. Read selection
(hand/machine) 3. Input milk value 4.
Squeeze 5. Read milk value 6. Squeeze 7. Read
milk value
8. Input neighbour_home value 9. Read
selection(neighbour/village) 10. Sell to
neighbours 11. Sell to village 12. Input money
value
13. Buy clothes 14. Read money value
Conditionlist
1. If peasant_tired yes (sel bm) 2. While milk
exist 4. If neighbour_home yes 5. While money
exist
40Pseudocode
PEASANT NEEDS MONEY Input peasant value IF
peasant_tired yes milk with machine ELSE
milk by hand ENDIF Input milk value
WHILE milk exist Squeeze Read milk value
ENDWHILE Input neighbour_home IF
neighbour_home yes sell milk to neighbours
ELSE sell milk in village ENDIF Input
money value WHILE money exist Buy clothes
for wife Read money value ENDWHILE
Operationlist
1. Input peasant value 2. Read selection
(hand/machine) 3. Input milk value 4.
Squeeze 5. Read milk value 6. Squeeze 7. Read
milk value
8. Input neighbour_home value 9. Read
selection(neighbour/village) 10. Sell to
neighbours 11. Sell to village 12. Input money
value
13. Buy clothes 14. Read money value
Conditionlist
1. If peasant_tired yes (sel bm) 2. While milk
exist 4. If neighbour_home yes 5. While money
exist
41Pseudocode
PEASANT NEEDS MONEY Input peasant value IF
peasant_tired yes milk with machine ELSE
milk by hand ENDIF Input milk value
WHILE milk exist Squeeze Read milk value
ENDWHILE Input neighbour_home IF
neighbour_home yes sell milk to neighbours
ELSE sell milk in village ENDIF Input
money value WHILE money exist Buy clothes
for wife Read money value ENDWHILE
Operationlist
1. Input peasant value 2. Read selection
(hand/machine) 3. Input milk value 4.
Squeeze 5. Read milk value 6. Squeeze 7. Read
milk value
8. Input neighbour_home value 9. Read
selection(neighbour/village) 10. Sell to
neighbours 11. Sell to village 12. Input money
value
13. Buy clothes 14. Read money value
Conditionlist
1. If peasant_tired yes (sel bm) 2. While milk
exist 4. If neighbour_home yes 5. While money
exist
42Pseudocode
PEASANT NEEDS MONEY Input peasant value IF
peasant_tired yes milk with machine ELSE
milk by hand ENDIF Input milk value
WHILE milk exist Squeeze Read milk value
ENDWHILE Input neighbour_home IF
neighbour_home yes sell milk to neighbours
ELSE sell milk in village ENDIF Input
money value WHILE money exist Buy clothes
for wife Read money value ENDWHILE
Operationlist
1. Input peasant value 2. Read selection
(hand/machine) 3. Input milk value 4.
Squeeze 5. Read milk value 6. Squeeze 7. Read
milk value
8. Input neighbour_home value 9. Read
selection(neighbour/village) 10. Sell to
neighbours 11. Sell to village 12. Input money
value
13. Buy clothes 14. Read money value
Conditionlist
1. If peasant_tired yes (sel bm) 2. While milk
exist 3. If neighbour_home yes 4. While money
exist
43Pseudocode
PEASANT NEEDS MONEY Input peasant value IF
peasant_tired yes milk with machine ELSE
milk by hand ENDIF Input milk value
WHILE milk exist Squeeze Read milk value
ENDWHILE Input neighbour_home IF
neighbour_home yes sell milk to neighbours
ELSE sell milk in village ENDIF Input
money value WHILE money exist Buy clothes
for wife Read money value ENDWHILE
Operationlist
1. Input peasant value 2. Read selection
(hand/machine) 3. Input milk value 4.
Squeeze 5. Read milk value 6. Squeeze 7. Read
milk value
8. Input neighbour_home value 9. Read
selection(neighbour/village) 10. Sell to
neighbours 11. Sell to village 12. Input money
value
13. Buy clothes 14. Read money value
Conditionlist
1. If peasant_tired yes (sel bm) 2. While milk
exist 3. If neighbour_home yes 4. While money
exist
44Pseudocode
PEASANT NEEDS MONEY Input peasant value IF
peasant_tired yes milk with machine ELSE
milk by hand ENDIF Input milk value
WHILE milk exist Squeeze Read milk value
ENDWHILE Input neighbour_home IF
neighbour_home yes sell milk to neighbours
ELSE sell milk in village ENDIF Input
money value WHILE money exist Buy clothes
for wife Read money value ENDWHILE
Operationlist
1. Input peasant value 2. Read selection
(hand/machine) 3. Input milk value 4.
Squeeze 5. Read milk value 6. Squeeze 7. Read
milk value
8. Input neighbour_home value 9. Read
selection(neighbour/village) 10. Sell to
neighbours 11. Sell to village 12. Input money
value
13. Buy clothes 14. Read money value
Conditionlist
1. If peasant_tired yes (sel bm) 2. While milk
exist 3. If neighbour_home yes 4. While money
exist
45Pseudocode
PEASANT NEEDS MONEY Input peasant value IF
peasant_tired yes milk with machine ELSE
milk by hand ENDIF Input milk value
WHILE milk exist Squeeze Read milk value
ENDWHILE Input neighbour_home IF
neighbour_home yes sell milk to neighbours
ELSE sell milk in village ENDIF Input
money value WHILE money exist Buy clothes
for wife Read money value ENDWHILE
Operationlist
1. Input peasant value 2. Read selection
(hand/machine) 3. Input milk value 4.
Squeeze 5. Read milk value 6. Squeeze 7. Read
milk value
8. Input neighbour_home value 9. Read
selection(neighbour/village) 10. Sell to
neighbours 11. Sell to village 12. Input money
value
13. Buy clothes 14. Read money value
Conditionlist
1. If peasant_tired yes (sel bm) 2. While milk
exist 3. If neighbour_home yes 4. While money
exist
46Pseudocode
PEASANT NEEDS MONEY Input peasant value IF
peasant_tired yes milk with machine ELSE
milk by hand ENDIF Input milk value
WHILE milk exist Squeeze Read milk value
ENDWHILE Input neighbour_home IF
neighbour_home yes sell milk to neighbours
ELSE sell milk in village ENDIF Input
money value WHILE money exist Buy clothes
for wife Read money value ENDWHILE
Operationlist
1. Input peasant value 2. Read selection
(hand/machine) 3. Input milk value 4.
Squeeze 5. Read milk value 6. Squeeze 7. Read
milk value
8. Input neighbour_home value 9. Read
selection(neighbour/village) 10. Sell to
neighbours 11. Sell to village 12. Input money
value
13. Buy clothes 14. Read money value
Conditionlist
1. If peasant_tired yes (sel bm) 2. While milk
exist 3. If neighbour_home yes 4. While money
exist
47Pseudocode
PEASANT NEEDS MONEY Input peasant value IF
peasant_tired yes milk with machine ELSE
milk by hand ENDIF Input milk value
WHILE milk exist Squeeze Read milk value
ENDWHILE Input neighbour_home IF
neighbour_home yes sell milk to neighbours
ELSE sell milk in village ENDIF Input
money value WHILE money exist Buy clothes
for wife Read money value ENDWHILE
Operationlist
1. Input peasant value 2. Read selection
(hand/machine) 3. Input milk value 4.
Squeeze 5. Read milk value 6. Squeeze 7. Read
milk value
8. Input neighbour_home value 9. Read
selection(neighbour/village) 10. Sell to
neighbours 11. Sell to village 12. Input money
value
13. Buy clothes 14. Read money value
Conditionlist
1. If peasant_tired yes (sel bm) 2. While milk
exist 3. If neighbour_home yes 4. While money
exist
48The endpart 2
49Solving 2nd degree equations
- Structure diagram
- Structure diagram to pseudocode
- Pseudocode to C programming
50Solving 2nd degree equations
Program structure
D
51Solving 2nd degree equations
Program structure
2nd degree equation
Information
52Solving 2nd degree equations
Program structure
2nd degree equation
Solve equation?
Information
While answer ¹ n or N
One equation
53Solving 2nd degree equations
Program structure
2nd degree equation
Solve equation?
Information
While answer ¹ n or N
One equation
Possible solution
Constant a
Constant c
Constant b
54Solving 2nd degree equations
Program structure
2nd degree equation
Solve equation?
Information
While answer ¹ n or N
One equation
Possible solution
Constant a
Constant c
Constant b
If D ³ 0
Solution
No real solution
55Solving 2nd degree equations
Program structure
2nd degree equation
Solve equation?
Information
While answer ¹ n or N
One equation
Possible solution
Constant a
Constant c
Constant b
If D ³ 0
If D 0
Two solutions
One solution
56Solving 2nd degree equations
Program structure
2nd degree equation
Information
2
1
Possible solution
Constant a
Constant c
Constant b
2
6
If D ³ 0
5
4
3
If D 0
11
Two solutions
One solution
7
9
8
10
57Solving equations
Solving 2nd degree equationsDisplay program
informationAsk if user would like to solve
an equation (y/n)While answer is not n or N
Input constant a Input constant b Input
constant c calculate D b²/(4a²)-c/a If D ³
0 If D 0 calculate x -b/(2a)
display x else calculate x1
-b/(2a)ÖD calculate x2 -b/(2a)-ÖD
display x1, x2 end if else display No
solution end if Ask if user would like to
solve an equation (y/n) end while
Pseudo coding
58Solving equations
Solving 2nd degree equationsDisplay program
informationAsk if user would like to solve
an equation (y/n)While answer is not n or N
Input constant a Input constant b Input
constant c calculate D b²/(4a²)-c/a If D ³
0 If D 0 calculate x -b/(2a)
display x else calculate x1
-b/(2a)ÖD calculate x2 -b/(2a)-ÖD
display x1, x2 end if else display No
solution end if Ask if user would like to
solve an equation (y/n) end while
Pseudo coding
Constant a
3
Information
1
2nd degree equation
2
Constant b
4
Solve equation?
One equation
While answer ¹ n or N
Constant c
5
7
If D 0
One solution
6
If D ³ 0
8
Time
9
Two solutions
Possible solution
10
11
2
Division
59Solving equations
Solving 2nd degree equationDisplay program
informationAsk if user would like to solve
an equation (y/n)While answer is not n or N
Input constant a Input constant b Input
constant c calculate D b²/(4a²)-c/a If D ³
0 If D 0 calculate x -b/(2a)
display x else calculate x1
-b/(2a)ÖD calculate x2 -b/(2a)-ÖD
display x1, x2 end if else display No
solution end if Ask if user would like to
solve an equation (y/n) end while
Pseudo coding
60Solving equations
Solving 2nd degree equationDisplay program
informationAsk if user would like to solve
an equation (y/n)While answer is not n or N
Input constant a Input constant b Input
constant c calculate D b²/(4a²)-c/a If D ³
0 If D 0 calculate x -b/(2a)
display x else calculate x1
-b/(2a)ÖD calculate x2 -b/(2a)-ÖD
display x1, x2 end if else display No
solution end if Ask if user would like to
solve an equation (y/n)end while
Pseudo coding
61Solving equations
Solving 2nd degree equationDisplay program
informationAsk if user would like to solve
an equation (y/n)While answer is not n or N
Input constant a Input constant b Input
constant c calculate D b²/(4a²)-c/a If D ³
0 If D 0 calculate x -b/(2a)
display x else calculate x1
-b/(2a)ÖD calculate x2 -b/(2a)-ÖD
display x1, x2 end if else display No
solution end if Ask if user would like to
solve an equation (y/n)end while
Pseudo coding
62Solving equations
Solving 2nd degree equationDisplay program
informationAsk if user would like to solve
an equation (y/n)While answer is not n or N
Input constant a Input constant b Input
constant c calculate D b²/(4a²)-c/a If D ³
0 If D 0 calculate x -b/(2a)
display x else calculate x1
-b/(2a)ÖD calculate x2 -b/(2a)-ÖD
display x1, x2 end if else display No
solution end if Ask if user would like to
solve an equation (y/n)end while
Pseudo coding
63Solving equations
Solving 2nd degree equationDisplay program
informationAsk if user would like to solve
an equation (y/n)While answer is not n or N
Input constant a Input constant b Input
constant c calculate D b²/(4a²)-c/a If D ³
0 If D 0 calculate x -b/(2a)
display x else calculate x1
-b/(2a)ÖD calculate x2 -b/(2a)-ÖD
display x1, x2 end if else display No
solution end if Ask if user would like to
solve an equation (y/n)end while
Pseudo coding
64Solving equations
Solving 2nd degree equationDisplay program
informationAsk if user would like to solve
an equation (y/n)While answer is not n or N
Input constant a Input constant b Input
constant c calculate D b²/(4a²)-c/a If D ³
0 If D 0 calculate x -b/(2a)
display x else calculate x1
-b/(2a)ÖD calculate x2 -b/(2a)-ÖD
display x1, x2 end if else display No
solution end if Ask if user would like to
solve an equation (y/n) end while
Pseudo coding
65Solving equations
Solving 2nd degree equationDisplay program
informationAsk if user would like to solve
an equation (y/n)While answer is not n or N
Input constant a Input constant b Input
constant c calculate D b²/(4a²)-c/a If D ³
0 If D 0 calculate x -b/(2a)
display x else calculate x1
-b/(2a)ÖD calculate x2 -b/(2a)-ÖD
display x1, x2 end if else display No
solution end if Ask if user would like to
solve an equation (y/n)end while
Pseudo coding
66Solving equations
Solving 2nd degree equationDisplay program
informationAsk if user would like to solve
an equation (y/n)While answer is not n or N
Input constant a Input constant b Input
constant c calculate D b²/(4a²)-c/a If D ³
0 If D 0 calculate x -b/(2a)
display x else calculate x1
-b/(2a)ÖD calculate x2 -b/(2a)-ÖD
display x1, x2 end if else display No
solution end if Ask if user would like to
solve an equation (y/n)end while
Pseudo coding
67Solving equations
Solving 2nd degree equationDisplay program
informationAsk if user would like to solve
an equation (y/n)While answer is not n or N
Input constant a Input constant b Input
constant c calculate D b²/(4a²)-c/a If D ³
0 If D 0 calculate x -b/(2a)
display x else calculate x1
-b/(2a)ÖD calculate x2 -b/(2a)-ÖD
display x1, x2 end if else display No
solution end if Ask if user would like to
solve an equation (y/n)end while
Pseudo coding
68Solving equations
Solving 2nd degree equationDisplay program
informationAsk if user would like to solve
an equation (y/n)While answer is not n or N
Input constant a Input constant b Input
constant c calculate D b²/(4a²)-c/a If D ³
0 If D 0 calculate x -b/(2a)
display x else calculate x1
-b/(2a)ÖD calculate x2 -b/(2a)-ÖD
display x1, x2 end if else display No
solution end if Ask if user would like to
solve an equation (y/n)end while
Pseudo coding
69Solving equations
Solving 2nd degree equationDisplay program
informationAsk if user would like to solve
an equation (y/n)While answer is not n or N
Input constant a Input constant b Input
constant c calculate D b²/(4a²)-c/a If D ³
0 If D 0 calculate x -b/(2a)
display x else calculate x1
-b/(2a)ÖD calculate x2 -b/(2a)-ÖD
display x1, x2 end if else display No
solution end if Ask if user would like to
solve an equation (y/n)end while
Pseudo coding
70Solving equations
Solving 2nd degree equationDisplay program
informationAsk if user would like to solve
an equation (y/n)While answer is not n or N
Input constant a Input constant b Input
constant c calculate D b²/(4a²)-c/a If D ³
0 If D 0 calculate x -b/(2a)
display x else calculate x1
-b/(2a)ÖD calculate x2 -b/(2a)-ÖD
display x1, x2 end if else display No
solution end if Ask if user would like to
solve an equation (y/n)end while
Pseudo coding
71Solving equations
Solving 2nd degree equationDisplay program
informationAsk if user would like to solve
an equation (y/n)While answer is not n or N
Input constant a Input constant b Input
constant c calculate D b²/(4a²)-c/a If D ³
0 If D 0 calculate x -b/(2a)
display x else calculate x1
-b/(2a)ÖD calculate x2 -b/(2a)-ÖD
display x1, x2 end if else display No
solution end if Ask if user would like to
solve an equation (y/n)end while
Pseudo coding
72Solving equations
Solving 2nd degree equationDisplay program
informationAsk if user would like to solve
an equation (y/n)While answer is not n or N
Input constant a Input constant b Input
constant c calculate D b²/(4a²)-c/a If D ³
0 If D 0 calculate x -b/(2a)
display x else calculate x1
-b/(2a)ÖD calculate x2 -b/(2a)-ÖD
display x1, x2 end if else display No
solution end if Ask if user would like to
solve an equation (y/n)end while
Pseudo coding
73Solving equations
Solving 2nd degree equationDisplay program
informationAsk if user would like to solve
an equation (y/n)While answer is not n or N
Input constant a Input constant b Input
constant c calculate D b²/(4a²)-c/a If D ³
0 If D 0 calculate x -b/(2a)
display x else calculate x1
-b/(2a)ÖD calculate x2 -b/(2a)-ÖD
display x1, x2 end if else display No
solution end if Ask if user would like to
solve an equation (y/n)end while
Pseudo coding
74Solving equations
Solving 2nd degree equationDisplay program
informationAsk if user would like to solve
an equation (y/n)While answer is not n or N
Input constant a Input constant b Input
constant c calculate D b²/(4a²)-c/a If D ³
0 If D 0 calculate x -b/(2a)
display x else calculate x1
-b/(2a)ÖD calculate x2 -b/(2a)-ÖD
display x1, x2 end if else display No
solution end if Ask if user would like to
solve an equation (y/n)end while
Pseudo coding
75Solving equations
Solving 2nd degree equationDisplay program
informationAsk if user would like to solve
an equation (y/n)While answer is not n or N
Input constant a Input constant b Input
constant c calculate D b²/(4a²)-c/a If D ³
0 If D 0 calculate x -b/(2a)
display x else calculate x1
-b/(2a)ÖD calculate x2 -b/(2a)-ÖD
display x1, x2 end if else display No
solution end if Ask if user would like to
solve an equation (y/n)end while
Pseudo coding
76Lego Mindstorms
77Lego Mindstorms
78Solving equations
Heres an example of translating the pseudocode
to C code
Program
79Solving equations
C coding
int main() char answer
Solving 2nd degree equations
Im lost in cyberspace
80Solving equations
C coding
int main() char answer
Solving 2nd degree equations
Im lost in cyberspace
81Solving equations
C coding
int main() char answer
Solving 2nd degree equations
Im lost in cyberspace
82Solving equations
C coding
int main() char answer
Solving 2nd degree equations
83Solving equations
C coding
int main() char answer info()
Solving 2nd degree equationsDisplay program
information
Dont worry! Youll C!!
84Solving equations
C coding
int main() char answer info()
answerask_again()
Solving 2nd degree equationsDisplay program
informationAsk if user would like to solve
an equation (y/n)
Aha, this doesnt seem to be that difficult!
85Solving equations
C coding
int main() char answer info()
answerask_again()
Solving 2nd degree equationsDisplay program
informationAsk if user would like to solve
an equation (y/n)
Make room! Ive got more to say!
86Solving equations
C coding
int main() char answer info()
answerask_again()
Solving 2nd degree equationsDisplay program
informationAsk if user would like to solve
an equation (y/n)
Make room! Ive got more to say!
87Solving equations
C coding
int main() char answer info()
answerask_again() while(answer ! n
answer ! N)
Solving 2nd degree equationsDisplay program
informationAsk if user would like to solve
an equation (y/n)While answer is not n or N
Make room! Ive got more to say!
88Solving equations
C coding
int main() char answer info()
answerask_again() while(answer ! n
answer ! N)
Solving 2nd degree equationsDisplay program
informationAsk if user would like to solve
an equation (y/n)While answer is not n or N
Make room! Ive got more to say!
89Solving equations
C coding
int main() char answer info()
answerask_again() while(answer ! n
answer ! N)
Solving 2nd degree equationsDisplay program
informationAsk if user would like to solve
an equation (y/n)While answer is not n or N
Make room! Ive got more to say!
90Solving equations
C coding
int main() char answer info()
answerask_again() while(answer ! n
answer ! N) printf(Input a b c with
spaces) scanf(lflflf, a, b, c)
Solving 2nd degree equationsDisplay program
informationAsk if user would like to solve
an equation (y/n)While answer is not n or N
Input constant a Input constant b Input
constant c
91Solving equations
C coding
int main() char answer info()
answerask_again() while(answer ! n
answer ! N) printf(Input a b c with
spaces) scanf(lflflf, a, b, c)
D pow(b, 2)/(4pow(a,2))-c/a
Solving 2nd degree equationsDisplay program
informationAsk if user would like to solve
an equation (y/n)While answer is not n or N
Input constant a Input constant b Input
constant c calculate D b²/(4a²)-c/a
92Solving equations
C coding
int main() char answer info()
answerask_again() while(answer ! n
answer ! N) printf(Input a b c with
spaces) scanf(lflflf, a, b, c)
D pow(b, 2)/(4pow(a,2))-c/a if (D gt 0)
if (D 0)
else
else
Solving 2nd degree equationsDisplay program
informationAsk if user would like to solve
an equation (y/n)While answer is not n or N
Input constant a Input constant b Input
constant c calculate D b²/(4a²)-c/a If D ³
0 If D 0 else end if else
end if
93Solving equations
C coding
int main() char answer info()
answerask_again() while(answer ! n
answer ! N) printf(Input a b c with
spaces) scanf(lflflf, a, b, c)
D pow(b, 2)/(4pow(a,2))-c/a if (D gt 0)
if (D 0)
else
else
Solving 2nd degree equationsDisplay program
informationAsk if user would like to solve
an equation (y/n)While answer is not n or N
Input constant a Input constant b Input
constant c calculate D b²/(4a²)-c/a If D ³
0 If D 0 else end if else
end if
94Solving equations
C coding
int main() char answer info()
answerask_again() while(answer ! n
answer ! N) printf(Input a b c with
spaces) scanf(lflflf, a, b, c)
D pow(b, 2)/(4pow(a,2))-c/a if (D gt 0)
if (D 0)
else
else
Solving 2nd degree equationsDisplay program
informationAsk if user would like to solve
an equation (y/n)While answer is not n or N
Input constant a Input constant b Input
constant c calculate D b²/(4a²)-c/a If D ³
0 If D 0 else end if else
end if
x -b/(2a)printf(One solution X.2lf \n,
x)
calculate x -b/(2a)display x
95Solving equations
C coding
int main() char answer info()
answerask_again() while(answer ! n
answer ! N) printf(Input a b c with
spaces) scanf(lflflf, a, b, c)
D pow(b, 2)/(4pow(a,2))-c/a if (D gt 0)
if (D 0) x
-b/(2a) printf(One solution
X.2lf\n, x) else
else
Solving 2nd degree equationsDisplay program
informationAsk if user would like to solve
an equation (y/n)While answer is not n or N
Input constant a Input constant b Input
constant c calculate D b²/(4a²)-c/a If D ³
0 If D 0 calculate x -b/(2a)
display x else end if else end
if
calculate x1 -b/(2a)ÖDcalculate x2
-b/(2a)-ÖDdisplay x1, x2
x1 -b/(2a) sqrt(D)x2 -b/(2a)-
sqrt(D)printf(Two solutions X1.2lf
X2.2lf\n, x1, x2)
96Solving equations
C coding
int main() char answer info()
answerask_again() while(answer ! n
answer ! N) printf(Input a b c with
spaces) scanf(lflflf, a, b, c)
D pow(b, 2)/(4pow(a,2))-c/a if (D gt 0)
if (D 0) x
-b/(2a) printf(One solution
X.2lf\n, x) else
x1 -b/(2a) sqrt(D) x2 -b/(2a)-
sqrt(D) printf(Two solutions X1.2lf
X2.2lf\n, x1, x2)
else
Solving 2nd degree equationsDisplay program
informationAsk if user would like to solve
an equation (y/n)While answer is not n or N
Input constant a Input constant b Input
constant c calculate D b²/(4a²)-c/a If D ³
0 If D 0 calculate x -b/(2a)
display x else calculate x1
-b/(2a)ÖD calculate x2 -b/(2a)-ÖD
display x1, x2 end if else end if
display No solution
printf(No solutions!\n)
97Solving equations
C coding
int main() char answer info()
answerask_again() while(answer ! n
answer ! N) printf(Input a b c with
spaces) scanf(lflflf, a, b, c)
D pow(b, 2)/(4pow(a,2))-c/a if (D gt 0)
if (D 0) x
-b/(2a) printf(One solution
X.2lf\n, x) else
x1 -b/(2a) sqrt(D) x2 -b/(2a)-
sqrt(D) printf(Two solutions X1.2lf
X2.2lf\n, x1, x2)
else printf(No solutions!\n)
answerask_again()
Solving 2nd degree equationsDisplay program
informationAsk if user would like to solve
an equation (y/n)While answer is not n or N
Input constant a Input constant b Input
constant c calculate D b²/(4a²)-c/a If D ³
0 If D 0 calculate x -b/(2a)
display x else calculate x1
-b/(2a)ÖD calculate x2 -b/(2a)-ÖD
display x1, x2 end if else display No
solution end if Ask if user would like to
solve an equation (y/n)end while
Program
98THE END