It is used by a programmer to decide whether the set of instructions is to be executed based on the condition whether it is TRUE or FALSE.
The decision logic structure uses the If/Then/Else instruction. It tells the computer that If a condition is true, Then execute a set of instructions, or Else execute another set of instructions. The Else part is optional, as there is not always a set of instructions if the conditions are false. When there are no instructions for true, a Continue statement must be used.
There are to TWO (2) types of condition, as follow:
Single condition: It has only two possible actions or set of instructions
Multiple conditions
Multiple Conditions
It has THREE (3) kinds of multiple conditions such as straight-through logic, positive logic, and negative logic.
Straight-through logic means that all of the decisions are processed sequentially, one after the other.straight-through logic is required when all the decisions have to be processed, and when they are independent of each other.
Problem : to find the amount to charge people of varying ages for a concert ticket. When the person is under 16, the charge is $7; when the person is 65 or over, the charge is $5; all others are charged $10.
Positive logic allows the flow of the processing to continue through the module instead of processing succeeding decisions. In general, when you use positive logic, you are telling the computer to follow a set of instructions and continue processing if the condition is True; If the condition is not True, then the computer processes another decision. When you use this logic, no more decisions are processed once the resultant of a condition is True.
Problem: To find the amount to charge people of varying ages for a concert ticket. When the person is under 16, the charge is $7; when the person is 65 or over, the charge is $5; all others are charged $10. The conditions of that problem are the following:
Negative logic is similar to positive logic except that the flow of the processing continues through the module when the resultant of decision is FALSE. In general, when you use negative logic you are telling the computer to process another decision when the resultant of the condition is True; If the resultant is False, then the computer processes a consequent set of instructions and continues processing the module. he hardest to use and understand
Problem: To find the amount to charge people of varying ages for a concert ticket. When the person is under 16, the charge is $7; when the person is 65 or over, the charge is $5; all others are charged $10.
Exercise
Develop the flowchart in Positive Logic and Negative Logic to determine whether a temperature is below or above the freezing point. The algorithm as follow:
Start
Read temperature
If the temperature is less than 32. then print “below freezing point”, otherwise print “above freezing point”
End
References:
Sprankle, Maureen (2001), Problem Solving and Programming Concepts, 5th edition, Prentice-Hall.
Jeri R. Hanly, Elliot B. Koffman (2003), Problem Solving and Program Design in C, 4th edition Addison Wesley
H.M. Deital, P.J. Deital (2001). C: How to Program. 3rd edition, Prentice-Hall.
Alice Ficher, Stephen M. Rass(2001), Applied C (An Introduction and Move) Mc Graw Hill, New Haven
Actually, we will always find problems in our daily life, so we’ve to solve the problems until we get the solutions. In this lecture, you’ll know how the steps used to solve the problems. Especially, according to computer literature, we use computer as a tool to solve the problems. As Programmer you should know the way to develop a program that used the right order of steps in developement of program.
People make decisions every day to solve problems that affect their lives. The problems may be as unimportant as what to watch on television or as important as choosing a new profession. If a bad decision is made, time and resources are wasted, so it’s important that people know how to make decisions well. There are six steps to follow to ensure the best decision. These six steps in problem solving include the following:
Identify the problem
Understand the problem
Identify the alrternative ways to solve the problem
Select the best way to solve the problem from the list of alternative solution
List instructions that enable you to solve the problem using the selected solution
Evaluate the Solution
The Example of Problem
Take the problem of what to do this evening
Identify the problem. How do the individuals wish to spend the evening
Understand the problem. With this simple problem, also, the knowledge base of the participants must be considered. The only solutions that should be selected are ones that everyone involved would know how to do. You probably would not select as a possible solution playing a game of chess if the participants did not know how to play.
Identify alternatives. Note : The list is complete only when you can think of no more alternatives.
Watch television.
Invite friends over.
Play video games.
Go to the movies.
Play miniature golf.
Go to the amusement park.
Go to a friend’s party.
Select the best way to solve the problem.
Weed out alternatives that are not acceptable, such as those that cost too much money or do not interest one of the individuals involved.
Specify the pros and cons of each remaining alternative.
Weigh the pros and cons to make the final decision. This solution will be the best alternative if all the other steps were completed well.
Prepare a list of steps (instructions) that will result in a fun evening.
Evaluate the solution. Are we having fun yet? If nobody is having fun, then the planner needs to review the steps to have a fun evening to see whether anything can be changed, if not then the process must start again.