Jump to content

Decision tables: Difference between revisions

→‎{{header|REXX}}: added/changed whitespace and comments, elided deadcode, added highlighting to the output, added a template for the output section.
(→‎{{header|REXX}}: added/changed whitespace and comments, elided deadcode, added highlighting to the output, added a template for the output section.)
Line 1,758:
::*   a method of allowing the user to quit (opt-out of) the interrogation
<lang rexx>/*REXX program demonstrates a (query) decision table and possible corrective actions.*/
Q.=; Q.1 = 'Does the printer not print?'
Q.2 = 'Is there a red light flashing on the printer?'
Q.3 = 'Is the printer unrecognized by the software?'
Q.0 = 3
action.= /* Y=yes N=no if character isn't a letter = don't care.*/
 
Line 1,769 ⟶ 1,768:
/* │││ */
/* ↓↓↓ */
action.1 = 'yny' ; pos.1 = '"═════════ Check the power cable.'"
action.2 = 'y.y' ; pos.2 = '"═════════ check the printer-computer cable.'"
action.3 = '..y' ; pos.3 = '"═════════ Ensure printer software is installed.'"
action.4 = '.y.' ; pos.4 = '"═════════ Check/replace ink.'"
action.5 = 'y.n' ; pos.5 = '"═════════ Check for paper jam.'"
 
do i=1 forwhile Q.0i\==''; ans.i= asker(i); end /*display the question, obtain response*/
end /*i*/; Q.0= i - 1 /*adjust Q.0 for the DO loop indexing. */
say /*display a blank line before questions*/
possible=0 0 /*we'll be counting possible solutions.*/
 
do k=1 while action.k\=='' /*filter the answers via decision table*/
 
do j=1; d= substr(action.k, j, 1); upper d
jm= j//Q.0; if jm==0 then jm= Q.0
if d==' ' then leave
if \datatype(d, 'U') then iterate
if d\==ans.jm then iterate k
if j==Q then leave
end /*j*/
say pos.k /*this could be a possible solution. */
possible= possible +1 1 /*count number of possible solutions. */
end /*k*/
 
if possible==0 then say 'No═════════ solutions givenThere are no solutions for the information supplied.'
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
asker: arg ?; oops= 0; Qprefix= copies('─', 9) '(question' ? "of" Q.0') '
howTo = '(You can answer with a Yes or No [or Quit])'
 
do forever
if oops then do; say; say right(howTo, 79); say; oops=0; end0
Q.0 = 3 end
say Qprefix Q.?; parse pull x /*ask question (after prompt)*/
x=strip(space(x),,'say Qprefix Q.')?; parse upper var parse pull x u 1 u1 2 /*u1=1stask characterquestion of(after answer.prompt)*/
ifx= wordsstrip(space(x)==0 then iterate , , .); parse upper var x u 1 u1 2 /*Nothingu1=1st entered?character Tryof againanswer.*/
if abbrevwords('QUIT',u,1x)==0 then exit then iterate /*user isNothing tiredentered? ofTry answeringagain.*/
if (abbrev('YESQUIT', u,1) | abbrev("NO",u))then &exit words(x)==1 then return u1 /*user is tired of answering.*/
sayif (abbrev('invalid response: YES', u) x; | abbrev("NO", u)) & oops words(x)==1 then return u1
say 'invalid response: ' x; oops= 1
end /*forever*/</lang>
'''{{out|output''' |text=&nbsp; (a screen scraping using a DOS prompt window for some of the possible responses):}}
 
DECISION('''decision.REXrex''' &nbsp; is the name of the REXX program that produced this output.)
<pre style="height:50ex">
D:\►rexx decision
Line 1,819 ⟶ 1,820:
n
 
No═════════ solutions givenThere are no solutions for the information supplied.
 
D:\►rexx decision
Line 1,829 ⟶ 1,830:
yes
 
═════════ Ensure printer software is installed.
 
D:\►rexx decision
Line 1,839 ⟶ 1,840:
n
 
═════════ Check/replace ink.
 
D:\►rexx decision
Line 1,849 ⟶ 1,850:
yes
 
═════════ Ensure printer software is installed.
═════════ Check/replace ink.
 
D:\►rexx decision
Line 1,860 ⟶ 1,861:
no
 
═════════ Check for paper jam.
 
D:\►rexx decision
Line 1,870 ⟶ 1,871:
y
 
═════════ Check the power cable.
═════════ check the printer-computer cable.
═════════ Ensure printer software is installed.
 
D:\►rexx decision
Line 1,882 ⟶ 1,883:
n
 
═════════ Check/replace ink.
═════════ Check for paper jam.
 
D:\►rexx decision
Line 1,893 ⟶ 1,894:
y
 
═════════ check the printer-computer cable.
═════════ Ensure printer software is installed.
═════════ Check/replace ink.
 
D:\►
Cookies help us deliver our services. By using our services, you agree to our use of cookies.