'===========================================================================
' Subject: DECISION ANALYSIS PROGRAM          Date: 10-17-99 (22:41)       
'  Author: Nathiel T. Tinsley                 Code: QB, QBasic, PDS        
'  Origin: ntins2000@email.msn.com          Packet: ALGOR.ABC
'===========================================================================
     REM **** DECISION MAKER. ****
     REM *** QBasic Version for PC's. ***
     GOTO TARGET1
TARGET41:
     DIM c$(2), a$(ad), f$(ad), f(ad), af(ad), t(ad), w(ad), r(ad, ad)
     REM *** TYPE OF DECISION. ***
     CLS
      PRINT h$
      PRINT d$
      PRINT
     PRINT " This Program can help you in making decisions by asking you for information"
     PRINT "which is then analysed in a systematic manner."
     PRINT
      PRINT "Please tell me which of the following most closely describes the type of"
     PRINT "Decision you are faced with :-"
     PRINT
      FOR j = 1 TO 2
      PRINT j; ". "; c$(j); "."
      NEXT j
TARGET4:
     PRINT
      PRINT TAB(9);
      INPUT "Which Number "; n$
     wd = INT(VAL(n$))
      IF wd = 1 THEN
         c$ = c$(wd)
          c1$ = MID$(c$, 19)
          GOTO TARGET2
     END IF
     IF wd <> 2 THEN
         GOSUB TARGET3
          GOTO TARGET4
     END IF
     CLS
      PRINT h3$
      PRINT d$
      PRINT
      PRINT
     INPUT "The Type of Object you are trying to Select is a(n) "; w$
     c$ = LEFT$(c$(2), 18) + w$
      c1$ = w$
     REM *** NAMES OF OBJECTS. ***
TARGET9:
     CLS
      PRINT c$
      PRINT d$
      PRINT
     PRINT " Please type in full, a list of every "; c1$; " under Consideration."
      PRINT s$
     PRINT " Enter one at each Prompt (Type 'F' to indicate that you have finished)."
      PRINT
      ta = 0
TARGET6:
     ta = ta + 1
      PRINT ta;
      INPUT a$(ta)
     IF UCASE$(a$(ta)) = "F" THEN
         ta = ta - 1
          GOTO TARGET5
     END IF
     IF ta < ad GOTO TARGET6
     
TARGET5:
     CLS
      PRINT c$
      PRINT d$
      PRINT
     FOR j = 1 TO ta
      PRINT j; ". "; a$(j)
      NEXT j
TARGET11:
     PRINT
      PRINT yn$;
      INPUT w$
     IF UCASE$(LEFT$(w$, 1)) = "Y" GOTO TARGET7
     
     IF UCASE$(LEFT$(w$, 1)) = "N" THEN
         GOSUB TARGET8
          GOTO TARGET9
     END IF
     GOSUB TARGET10
      GOTO TARGET11
TARGET2:
     PRINT h1$
      PRINT d$
      PRINT
     REM *** COURSE OF ACTION. ***
     PRINT " Please enter all the courses of Action between which you have to decide."
      PRINT s$
     PRINT "Enter one at each Prompt (Type 'F' to indicate you have Finished)."
      PRINT
      ta = 0
TARGET13:
     ta = ta + 1
      PRINT ta; ". ";
      INPUT a$(ta)
     IF UCASE$(a$(ta)) = "F" THEN
         ta = ta - 1
          GOTO TARGET12
     END IF
     IF ta < ad GOTO TARGET13
     
TARGET12:
     PRINT h1$
      PRINT d$
      PRINT
     FOR j = 1 TO ta
      PRINT j; ". "; a$(j)
      NEXT j
TARGET14:
     PRINT
      PRINT yn$;
      INPUT w$
     IF UCASE$(LEFT$(w$, 1)) = "N" THEN
         GOSUB TARGET8
          GOTO TARGET2
     END IF
     IF UCASE$(LEFT$(w$, 1)) <> "Y" THEN
         GOSUB TARGET8
          GOTO TARGET14
     END IF
     REM *** LIST OF FACTORS. ***
TARGET7:
     tf = 0
      CLS
      PRINT h2$
      PRINT d$
      PRINT
     PRINT " Which Factors are important to you when "; c$; "?"
     PRINT "Please enter these Factors one at a time after each Prompt (Type 'F' to"
     PRINT "indicate that you have finished)."
      PRINT
TARGET16:
     tf = tf + 1
      PRINT tf; ". ";
      INPUT f$(tf)
     IF UCASE$(f$(tf)) = "F" THEN
         tf = tf - 1
          GOTO TARGET15
     END IF
     IF tf < ad GOTO TARGET16
     
TARGET15:
     CLS
      PRINT h2$
      PRINT d$
      PRINT
      FOR j = 1 TO tf
      PRINT j; ". "; f$(j); "."
      NEXT j
TARGET17:
     PRINT
      PRINT yn$
      INPUT w$
     IF UCASE$(LEFT$(w$, 1)) = "N" THEN
         GOSUB TARGET8
          GOTO TARGET7
     END IF
     IF UCASE$(LEFT$(w$, 1)) <> "Y" THEN
         GOSUB TARGET10
          GOTO TARGET17
     END IF
     PRINT
      PRINT "Please select the one you regard as the most important."
TARGET18:
     PRINT
      INPUT "Number "; w$
     m = INT(VAL(w$))
      IF (m < 1) + (m > tf) THEN
         GOSUB TARGET3
          GOTO TARGET18
     END IF
     REM *** RATE THE FACTOR. ***
TARGET21:
     f(m) = 20
      CLS
      PRINT h4$
      PRINT d$
     PRINT
      PRINT " As you deemed it the most important, let's award the top rating of 20 marks"
     PRINT "to the "; f$(m); " Factor."
     PRINT " Using this Scale, please give a rating from 0.1 to 19.9 to the other Factors :-"
      PRINT
     t = 20
      FOR j = 1 TO tf
      IF j = m GOTO TARGET19
     
TARGET20:
     PRINT f$(j);
      INPUT w$
      r = INT(VAL(w$))
     IF (r < .1) + (r > 19.9) THEN
         GOSUB TARGET3
          GOTO TARGET20
     END IF
     f(j) = r
      t = t + r
TARGET19:
     NEXT j
      CLS
      PRINT h4$
      PRINT d$
      PRINT
     FOR j = 1 TO tf
      PRINT j; ". "; f$(j), f(j)
      NEXT j
TARGET22:
     PRINT
      PRINT yn$;
      INPUT w$
     IF UCASE$(LEFT$(w$, 1)) = "N" THEN
         GOSUB TARGET8
          GOTO TARGET21
     END IF
     IF UCASE$(LEFT$(w$, 1)) <> "Y" THEN
         GOSUB TARGET10
          GOTO TARGET22
     END IF
     FOR j = 1 TO tf
      af(j) = f(j) / t
      NEXT j
     REM *** COMPARE AGAINST EACH OTHER. ***
TARGET24:
     CLS
      PRINT h5$
      PRINT d$
      PRINT
     PRINT " We will now take one Factor at a time and consider that Factor against every"
     PRINT c1$; "."
      PRINT
      PRINT
     PRINT " In order to have a yardstick for each factor, we will give a mark of 20 to the "; a$(1); " option."
     PRINT
      PRINT "Every other "; c1$; " will be awarded a mark higher or lower than 20"
     PRINT "for that factor, depending on whether you think it better or worse than the "
      PRINT a$(1); " option."
TARGET25:
     PRINT
      INPUT "Are you ready (y/n) "; w$
     IF UCASE$(LEFT$(w$, 1)) = "Y" GOTO TARGET23
     
     IF UCASE$(LEFT$(w$, 1)) = "N" GOTO TARGET24
     
     GOSUB TARGET10
      GOTO TARGET25
TARGET23:
     hs = 0
      FOR j = 1 TO tf
      t = 20
      r(j, 1) = 20
     FOR h = 2 TO ta
      CLS
      PRINT f$(j); " Comparisons."
      PRINT d$
     FOR l = 1 TO h - 1
      PRINT a$(l); " Rating ="; r(j, l)
      NEXT l
      PRINT d$
TARGET26:
     PRINT
      PRINT "What mark (higher or lower than 20) do you wish to assign to "
     PRINT a$(l); " for "; f$(j);
      INPUT w$
      n = VAL(w$)
     IF n < .1 THEN
         GOSUB TARGET3
          GOTO TARGET26
     END IF
     t = t + n
      r(j, h) = n
      NEXT h
     FOR h = 1 TO ta
      t(h) = t(h) + ((r(j, h) / t) * af(j))
      IF t(h) > hs THEN
         hs = t(h)
     END IF
     NEXT h, j
TARGET40:
     CLS
      PRINT h$
      PRINT d$
      FOR j = 1 TO 5
      PRINT
      NEXT j
      PRINT d$
      PRINT
     PRINT " Data now being analysed and sorted. The winner will be given 100 marks and"
     PRINT "the rest adjusted accordingly."
      PRINT
      PRINT d$
      GOSUB TARGET27
     REM *** STANDARDISE AND SORT THE MARKS. ***
     FOR j = 1 TO ta
      t(j) = INT((t(j) * 100 / hs) * 100) / 100
      NEXT j
     FOR j = 1 TO ta
      w(j) = j
      NEXT j
     k = ta
      FOR j = 1 TO ta
      k = k - 1
      FOR h = 1 TO k
      IF t(w(h)) > t(w(h + 1)) GOTO TARGET28
     
     w = w(h)
      w(h) = w(h + 1)
      w(h + 1) = w
TARGET28:
     NEXT h, j
     REM *** PRINT RESULTS. ***
     CLS
      PRINT h$
      PRINT d$
      PRINT
     h = t(w(1)) - t(w(2))
      IF h = 0 THEN
         PRINT "It's a Dead Heat!!"
          GOTO TARGET29
     END IF
     PRINT a$(w(1)); " is the Winner,";
     IF h > 25 THEN
         PRINT " by a wide margin."
          GOTO TARGET29
     END IF
     IF h > 15 THEN
         PRINT " by a comfortable margin."
          GOTO TARGET29
     END IF
     IF h > 5 THEN
         PRINT " by a small margin."
          GOTO TARGET29
     END IF
     PRINT " by a narrow margin."
TARGET29:
     PRINT d$
      PRINT
      FOR j = 1 TO ta
      w = w(j)
      PRINT a$(w); " "; t(w)
      NEXT
      PRINT
TARGET30:
     PRINT d$
      PRINT "Do you wish to (R)evise the contents, (S)tart a new analysis or (E)nd ";
      INPUT a$
     IF UCASE$(LEFT$(a$, 1)) = "S" THEN
         RUN
     END IF
     IF UCASE$(LEFT$(a$, 1)) = "E" THEN
         END
     END IF
     IF UCASE$(LEFT$(a$, 1)) <> "R" THEN
         GOSUB TARGET10
          GOTO TARGET30
     END IF
TARGET32:
     PRINT
      PRINT "Do you want to alter the significant factor scale (y/n) ";
      INPUT a$
     IF UCASE$(LEFT$(a$, 1)) = "N" GOTO TARGET31
     
     IF UCASE$(LEFT$(a$, 1)) <> "Y" THEN
         GOSUB TARGET10
          GOTO TARGET32
     END IF
     REM *** REVISE FACTOR RATINGS. ***
     CLS
      PRINT h4$
      PRINT d$
      PRINT
      FOR j = 1 TO tf
      PRINT j; ". "; f$(j), f(j)
      NEXT j
TARGET34:
     PRINT
      PRINT fc$;
      INPUT w$
      IF UCASE$(LEFT$(w$, 1)) = "F" GOTO TARGET33
     
     j = VAL(w$)
      IF (j < 1) + (j > tf) THEN
         GOSUB TARGET3
          GOTO TARGET34
     END IF
TARGET35:
     PRINT "What is the new rating (0.1 to 20) for "; f$(j);
      INPUT w$
     r = VAL(w$)
      IF (r < .1) + (r > 20) THEN
         GOSUB TARGET3
          GOTO TARGET35
     END IF
     f(j) = r
      GOTO TARGET32
TARGET33:
     t = 0
      FOR j = 1 TO tf
      t = t + f(j)
      NEXT j
      FOR j = 1 TO tf
      af(j) = f(j) / t
      NEXT j
     REM *** REVISE THE MARKINGS. ***
TARGET31:
     FOR j = 1 TO ta
      t(j) = 0
      NEXT j
      hs = 0
      FOR j = 1 TO tf
TARGET39:
     CLS
      PRINT f$(j); " Comparisons."
      PRINT d$
      PRINT
     FOR h = 1 TO ta
      PRINT th; ". "; a$(h); " Rating ="; r(j, h)
      NEXT h
TARGET37:
     PRINT
      PRINT rc$;
      INPUT w$
      IF UCASE$(LEFT$(w$, 1)) = "F" GOTO TARGET36
     
     l = VAL(w$)
      IF (l < 1) + (l > ta) THEN
         GOSUB TARGET3
          GOTO TARGET37
     END IF
TARGET38:
     PRINT
      PRINT "What is the new rating (Minimum .1) for "; a$(l)
     INPUT w$
      r = VAL(w$)
      IF r < .1 THEN
         GOSUB TARGET3
          GOTO TARGET38
     END IF
     r(j, l) = r
      GOTO TARGET39
TARGET36:
     t = 0
      FOR h = 1 TO ta
      t = t + r(j, h)
      NEXT h
     FOR h = 1 TO ta
      t(h) = t(h) + ((r(j, h) / t) * af(j))
      IF t(h) > hs THEN
         hs = t(h)
     END IF
     NEXT h, j
      GOTO TARGET40
     REM **** SUBROUTINES. ****
TARGET10:
     PRINT
      PRINT u$
      RETURN
TARGET3:
     PRINT
      PRINT wg$
      RETURN
TARGET8:
     PRINT
      PRINT re$
TARGET27:
     SLEEP 4
      RETURN
     REM ***** INITIALISE. *****
TARGET1:
     s$ = "The order is of no significance."
     h$ = "                                  DECISION MAKER."
     d$ = "--------------------------------------------------------------------------------"
     u$ = "I do not understand!"
     fc$ = "Which factor do you wish to alter   (Type 'F' if Finished)."
     rc$ = "Which rating do you wish to alter   (Type 'F' if Finished)."
     h1$ = "      Alternative courses of action"
     h2$ = "                Significant factors"
     h3$ = "                 Type of object"
     h4$ = "                 Factor ratings"
     h5$ = "               Comparison ratings"
     re$ = "Please enter them again."
     wg$ = "                   Invalid Entry  -  Please try again."
     yn$ = "Are these correct  (y/n) "
     ad = 50
      j = 0
      k = 0
      t = 0
     c$(1) = "Choosing the Best course of Action."
     c$(2) = "Choosing the Best Object."
     GOTO TARGET41
