Finish ing the logic flowc harts from week 3.. if invcd = A and (amtfst 500 or amtsnd 200) move...

25
Fini shin g the logi c flow char ts from week 3.

description

The pseudocode can be written with one if as shown previously, 3 separate if statements or two if statements as shown next.

Transcript of Finish ing the logic flowc harts from week 3.. if invcd = A and (amtfst 500 or amtsnd 200) move...

Page 1: Finish ing the logic flowc harts from week 3.. if invcd = A and (amtfst  500 or amtsnd  200) move OKAY to msg end if With the parenthesis, invcd.

Finishingthe logicflowchartsfromweek 3.

Page 2: Finish ing the logic flowc harts from week 3.. if invcd = A and (amtfst  500 or amtsnd  200) move OKAY to msg end if With the parenthesis, invcd.

if invcd = “A” and (amtfst > 500 or amtsnd > 200) move “OKAY” to msgend if

With the parenthesis, invcd has to be A and either of the other things have to be true. Without parenthesis, the things around the AND get resolved together and the criteria after the OR stands alone.The logic rule is that ANDs are resolved before ORs meaning that the conditions on either side of the AND are grouped.

Page 3: Finish ing the logic flowc harts from week 3.. if invcd = A and (amtfst  500 or amtsnd  200) move OKAY to msg end if With the parenthesis, invcd.

The pseudocode can be written with one if as shownpreviously, 3 separate ifstatements or two if statementsas shown next.

Page 4: Finish ing the logic flowc harts from week 3.. if invcd = A and (amtfst  500 or amtsnd  200) move OKAY to msg end if With the parenthesis, invcd.

This shows one if statement asking about invcd = "A" and then a second if statement that asksthe either or question only if the code is A.

Page 5: Finish ing the logic flowc harts from week 3.. if invcd = A and (amtfst  500 or amtsnd  200) move OKAY to msg end if With the parenthesis, invcd.

Without the parenthesisthe amtsnd > 200 standsalone so I need to ask itif I get a no to either of thequestions in the group.

Page 6: Finish ing the logic flowc harts from week 3.. if invcd = A and (amtfst  500 or amtsnd  200) move OKAY to msg end if With the parenthesis, invcd.

For easier coding, I canask the standalone question first.

Page 7: Finish ing the logic flowc harts from week 3.. if invcd = A and (amtfst  500 or amtsnd  200) move OKAY to msg end if With the parenthesis, invcd.

In this case, I have to askeach question separatelybecause I have differentactions.

Page 8: Finish ing the logic flowc harts from week 3.. if invcd = A and (amtfst  500 or amtsnd  200) move OKAY to msg end if With the parenthesis, invcd.

Now I am starting to look at SQL or sequel as it can also be called. SQL is the query language that is really executed when you put code into the user interface as we have been doing. You can also write SQL directly.Here I went into the user interface and picked the table I wanted to use. Then I went over to the view icon and hit the arrow beneath it and selected SQL view.Note that I am showing the code in notepad (I cut and pasted) so it is more readable - that has nothing to do with Access.

The select * means show all fields.The from tells what table to use. Note that SQL ends with a semi-colon.

Page 9: Finish ing the logic flowc harts from week 3.. if invcd = A and (amtfst  500 or amtsnd  200) move OKAY to msg end if With the parenthesis, invcd.
Page 10: Finish ing the logic flowc harts from week 3.. if invcd = A and (amtfst  500 or amtsnd  200) move OKAY to msg end if With the parenthesis, invcd.

If I want to only show specific fields, I can list them. Be careful to only use field names defined in the table you are using. In this case, the table is stu.

Page 11: Finish ing the logic flowc harts from week 3.. if invcd = A and (amtfst  500 or amtsnd  200) move OKAY to msg end if With the parenthesis, invcd.

This is what it would have looked like if I had done it in the user interface.

Page 12: Finish ing the logic flowc harts from week 3.. if invcd = A and (amtfst  500 or amtsnd  200) move OKAY to msg end if With the parenthesis, invcd.

Now I am adding criteria. I only want to see the records where gpa is greater than 3.This is like entering > 3 below the gpa column in the user interface.

Page 13: Finish ing the logic flowc harts from week 3.. if invcd = A and (amtfst  500 or amtsnd  200) move OKAY to msg end if With the parenthesis, invcd.

When you do comparisons whether in SQL or the user interface, you should compare things of the same type. Compare two numbers or two text fields.In this case gpa was defined in my table as a number and I am comparing to the number 3.

Page 14: Finish ing the logic flowc harts from week 3.. if invcd = A and (amtfst  500 or amtsnd  200) move OKAY to msg end if With the parenthesis, invcd.

Now I am doing an AND where both criteria have to be true. Note also that major was defined as text and CI is in quotes.

Page 15: Finish ing the logic flowc harts from week 3.. if invcd = A and (amtfst  500 or amtsnd  200) move OKAY to msg end if With the parenthesis, invcd.

This shows the results. All records are CI majors with gpa > 3.

Page 16: Finish ing the logic flowc harts from week 3.. if invcd = A and (amtfst  500 or amtsnd  200) move OKAY to msg end if With the parenthesis, invcd.
Page 17: Finish ing the logic flowc harts from week 3.. if invcd = A and (amtfst  500 or amtsnd  200) move OKAY to msg end if With the parenthesis, invcd.

Now I have change to an OR so one of these has to be true.

Page 18: Finish ing the logic flowc harts from week 3.. if invcd = A and (amtfst  500 or amtsnd  200) move OKAY to msg end if With the parenthesis, invcd.

Now I want to test for major = "CI" and one of the other criteria must be true. These other two criteria are in an OR relationship.

Page 19: Finish ing the logic flowc harts from week 3.. if invcd = A and (amtfst  500 or amtsnd  200) move OKAY to msg end if With the parenthesis, invcd.
Page 20: Finish ing the logic flowc harts from week 3.. if invcd = A and (amtfst  500 or amtsnd  200) move OKAY to msg end if With the parenthesis, invcd.

Here I did not put in the parenthesis so I would get the wrong results.I need to add the parenthesis to get the situation where it has to be a CI major and then either of the other criteria.

SELECT stuid, stuname, major, numcr, gpaFROM stuWHERE major = "CI" and (numcr > 20 or gpa > 3);

Page 21: Finish ing the logic flowc harts from week 3.. if invcd = A and (amtfst  500 or amtsnd  200) move OKAY to msg end if With the parenthesis, invcd.

This shows the results once I put in the parenthesis.

Page 22: Finish ing the logic flowc harts from week 3.. if invcd = A and (amtfst  500 or amtsnd  200) move OKAY to msg end if With the parenthesis, invcd.

Now I am showing the user interface where CI does not have to be true. I can have either CI and numcr > 18ORgpa > 3.2

Page 23: Finish ing the logic flowc harts from week 3.. if invcd = A and (amtfst  500 or amtsnd  200) move OKAY to msg end if With the parenthesis, invcd.

This is the way Microsoft writes it. Note the stu.stuid where the table name is put in before the field. I have table name dot field name.Also note the many many parenthesis.

Page 24: Finish ing the logic flowc harts from week 3.. if invcd = A and (amtfst  500 or amtsnd  200) move OKAY to msg end if With the parenthesis, invcd.

This is the simplified version.

Page 25: Finish ing the logic flowc harts from week 3.. if invcd = A and (amtfst  500 or amtsnd  200) move OKAY to msg end if With the parenthesis, invcd.