Anonymous user
Decision tables: Difference between revisions
→{{header|REXX}}: rewrote the REXX program for more positive logic (as opposed to negative logice), corrected a misspelling. -- ~~~~
(Added JavaScript) |
(→{{header|REXX}}: rewrote the REXX program for more positive logic (as opposed to negative logice), corrected a misspelling. -- ~~~~) |
||
Line 796:
This REXX example shows how one version of a decision table could be implemented,
<br>There was additional support added to the code for:
* a ''no solution found'' message
* a ''don't care'' requirement (regarding the decision table)
* a method of specifying
* used a minimalistic way in expressing the decision table
* extra prompting when there was a user reponse error
Line 805:
* a method of allowing the user to quit the interrogation
<lang rexx>/*REXX pgm demonstrates a decision table and possible corrective actions*/
Q.0 = 3
set=set-1 /*adjust SET (number of ? asked)*/▼
act.= /* Y = yes N = no not letter = don't care. */
/* ┌───────◄ answer to 1st question
/* │┌──────◄
/* ││┌─────◄
/* │││ */
/* ↓↓↓ */
act.1 = 'yny' ; pos.1 = 'Check the power cable.'
act.2 = 'y.y' ; pos.2 = 'check the printer-computer cable.'
act.3 = '..y' ; pos.3 = 'Ensure printer software is installed.'
act.4 = '.y.' ; pos.4 = 'Check/replace ink.'
act.5 = 'y.n' ; pos.5 = 'Check for paper jam.'
end /*i*/▼
say
possible=0 /*we'll be counting possible sols*/
do k=1 while act.k\=='' /*filter answers via decision tab*/
do j=1; d=substr(act.k,j,1); upper d
if
say pos.k /*this could be a possible sol. */
possible=possible+1 /*count num of possible solutions*/
Line 849 ⟶ 843:
exit /*stick a fork in it, we're done.*/
/*───────────────────────────────────ASKER subroutine───────────────────*/
asker: arg ?; oops=0; Qprefix=copies('─',9) '(question' ? "of"
howTo = '(You can answer with a Yes or No [or Quit])'
do forever▼
if words(ans)==0 then iterate /*nothing entered? Try again. */▼
if abbrev('QUIT',ansU,1) then exit /*the user is tired of answering.*/▼
if (\abbrev('YES',ansU,1) & \abbrev('NO',ansu,1)) |,▼
if oops
say Qprefix Q.?; parse pull x /*ask a question (after a
x=space(x); parse upper var x u 1 u1 2 /*u=upper(x); u1=1st
end /*forever*/</lang>▼
say 'invalid response: ' x; oops=1
'''output''' (a screen scraping using a DOS prompt window for the possible responses)
DECISION.REX is the REXX program that produced this output.
|