Decision tables: Difference between revisions
Content added Content deleted
m (→{{header|Quackery}}: tweaked comments) |
(Added XPL0 example.) |
||
Line 2,976: | Line 2,976: | ||
{{out}} |
{{out}} |
||
Sample input/output: |
Sample input/output: |
||
<pre> |
|||
Please answer the following questions with a y or n: |
|||
Printer prints ? n |
|||
A red light is flashing ? n |
|||
Printer is recognized by computer ? n |
|||
Recommended action(s): |
|||
Check the power cable |
|||
Check the printer-computer cable |
|||
Ensure printer software is installed |
|||
</pre> |
|||
=={{header|XPL0}}== |
|||
{{trans|Wren}} |
|||
<syntaxhighlight lang "XPL0">include xpllib; \for ToUpper, Print |
|||
int Conditions, Actions, NC, NA, NR, NP, Answers(3), Input, Outer, YN, R, C, A; |
|||
char S; |
|||
[Conditions:= [ |
|||
["Printer prints" , "NNNNYYYY"], |
|||
["A red light is flashing" , "YYNNYYNN"], |
|||
["Printer is recognized by computer", "NYNYNYNY"] |
|||
]; |
|||
Actions:= [ |
|||
["Check the power cable" , "NNYNNNNN"], |
|||
["Check the printer-computer cable" , "YNYNNNNN"], |
|||
["Ensure printer software is installed", "YNYNYNYN"], |
|||
["Check/replace ink" , "YYNNNYNN"], |
|||
["Check for paper jam" , "NYNYNNNN"] |
|||
]; |
|||
NC:= 3; |
|||
NA:= 5; |
|||
NR:= 8; \number of rules |
|||
NP:= 7; \index of 'no problem' rule |
|||
Print("Please answer the following questions with a y or n:\n"); |
|||
for C:= 0 to NC-1 do |
|||
[loop [Print(" %s ? ", Conditions(C,0)); |
|||
OpenI(0); |
|||
Input:= ToUpper(ChIn(0)); |
|||
if Input = ^Y or Input = ^N then quit; |
|||
]; |
|||
Answers(C):= Input = ^Y; |
|||
]; |
|||
Print("\nRecommended action(s):\n"); |
|||
for R:= 0 to NR-1 do |
|||
[Outer:= false; |
|||
for C:= 0 to NC-1 do |
|||
[YN:= if Answers(C) then ^Y else ^N; |
|||
S:= Conditions(C,1); \to access character bytes not integers |
|||
if S(R) # YN then |
|||
[Outer:= true; |
|||
C:= NC; \break |
|||
]; |
|||
]; |
|||
if not Outer then |
|||
[if R = NP then |
|||
Print(" None (no problem detected)\n") |
|||
else [for A:= 0 to NA-1 do |
|||
[S:= Actions(A,1); |
|||
if S(R) = ^Y then |
|||
Print(" %s\n", Actions(A,0)); |
|||
]; |
|||
]; |
|||
R:= NR; \break |
|||
]; |
|||
]; |
|||
]</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
<pre> |
||
Please answer the following questions with a y or n: |
Please answer the following questions with a y or n: |