home *** CD-ROM | disk | FTP | other *** search
/ MikeOS 4.5 / mikeos.iso / mikeos.flp / calc.bas < prev    next >
Encoding:
BASIC Source File  |  2014-12-21  |  5.4 KB  |  270 lines

  1. rem Calculator Application (CALC.BAS)
  2. rem A simple calculator application.
  3. rem Version 2.0.1
  4. rem Made by Joshua Beck
  5. rem Released under the GNU General Public Licence version 3
  6. rem Send any bugs, ideas or comments to mikeosdeveloper@gmail.com
  7.  
  8. rem Uses the MB++ Library version 3.0
  9. rem Avaliable at code.google.com/p/mikebasic-applications
  10. INCLUDE "MBPP.BAS"
  11.  
  12. START:
  13.   CLS
  14.   REM MB++ initialise function
  15.   GOSUB STARTPRG
  16.   REM set the text colour and highlight (for the menu)
  17.   C = 3
  18.   H = 11
  19.   REM set the box colour
  20.   T = 2
  21.   MOVE 30 13
  22.   PRINT "Calculating..."
  23. GOTO MAIN
  24.  
  25. MAIN:
  26.   REM main menu
  27.   $T = "Calculator"
  28.   $5 = "Simple Calculations"
  29.   $6 = "Advanced Maths"
  30.   $7 = "Change Colour Scheme"
  31.   $8 = "About"
  32.   $9 = "Exit"
  33.   GOSUB MENUBOX
  34.   IF V = 1 THEN GOSUB BASEMATH
  35.   IF V = 2 THEN GOSUB ADVMATH
  36.   IF V = 3 THEN GOSUB COLCHANGE
  37.   IF V = 4 THEN GOSUB ABOUT
  38.   IF V = 5 THEN GOSUB ENDPROG
  39. GOTO MAIN
  40.  
  41. COLCHANGE:
  42.   $T = "Change Colour Scheme"
  43.   $5 = "Input a new colour for outline, 1-255"
  44.   $6 = "Input a new text colour, 1-15"
  45.   V = 0
  46.   GOSUB DINBOX
  47.   $E = "Invalid colour"
  48.   IF A < 1 THEN GOTO ERRBOX
  49.   IF A > 255 THEN GOTO ERRBOX
  50.   IF B < 1 THEN GOTO ERRBOX
  51.   IF B > 15 THEN GOTO ERRBOX
  52.   T = A
  53.   C = B
  54.   $5 = "Input a new highlight colour, 1-15"
  55.   $6 = ""
  56.   V = 0
  57.   GOSUB INPBOX
  58.   $E = "Invalid colour"
  59.   IF V < 1 THEN GOTO ERRBOX
  60.   IF V > 15 THEN GOTO ERRBOX
  61.   H = V
  62. RETURN
  63.   
  64. BASEMATH:
  65.   REM start the menu loop
  66.   DO
  67.     REM set the menu title
  68.     $T = "Simple Calculations"
  69.     REM set items in the menu
  70.     $5 = "Addition"
  71.     $6 = "Subtraction"
  72.     $7 = "Multiplication"
  73.     $8 = "Division"
  74.     $9 = "Back"
  75.     REM call a menu
  76.     GOSUB MENUBOX
  77.     REM find out what they selected and gosub there
  78.     IF V = 1 THEN GOSUB ADD
  79.     IF V = 2 THEN GOSUB SUB
  80.     IF V = 3 THEN GOSUB MUL
  81.     IF V = 4 THEN GOSUB DIV
  82.   REM present the menu again unless 'back' was selected
  83.   LOOP UNTIL V = 5
  84.   V = 0
  85. RETURN
  86.  
  87. ADD:
  88.   REM INPBOX and DINBOX use V to choose between text and numerical input
  89.   REM we want numerical
  90.   V = 0
  91.   REM set the title
  92.   $T = "Addition"
  93.   REM first input prompt
  94.   $5 = "Input first number..."
  95.   REM second input prompt
  96.   $6 = "Input second number..."
  97.   REM DINBOX is similar to INPBOX (Print text and asks for input) but
  98.   REM it asks for two inputs rather than just one.
  99.   GOSUB DINBOX
  100.   REM do the actual calculation
  101.   REM the first input is A and the second is B
  102.   a = a + b
  103.   REM prompt above first number
  104.   $5 = "Answer is:"
  105.   REM prompt about second
  106.   REM this is set to a blank string so it won't print it (we only need one)
  107.   $6 = ""
  108.   REM call a number box to print our answer
  109.   GOSUB NUMBOX
  110.   REM back to main menu
  111. RETURN
  112.  
  113. SUB:
  114.   v = 0
  115.   $T = "Subtraction"
  116.   $5 = "Input number to subtract from..."
  117.   $6 = "Input number to subtract..."
  118.   GOSUB DINBOX
  119.   A = A - B
  120.   $5 = "Answer is:"
  121.   $6 = ""
  122.   GOSUB NUMBOX
  123. RETURN
  124.  
  125. MUL:
  126.   v = 0
  127.   $T = "Multiplication"
  128.   $5 = "Input first number..."
  129.   $6 = "Input second number..."
  130.   GOSUB DINBOX
  131.   A = A * B
  132.   $5 = "Answer is:"
  133.   $6 = ""
  134.   GOSUB NUMBOX
  135. RETURN
  136.  
  137. DIV:
  138.   v = 0
  139.   $T = "Division"
  140.   $5 = "Input number to be divided..."
  141.   $6 = "Input number to divide by..."
  142.   GOSUB DINBOX
  143.   REM define error message
  144.   REM if the divisor is zero then present this error
  145.   $E = "Attempted to divide by zero!"
  146.   IF B = 0 THEN GOTO ERRBOX
  147.   D = A / B
  148.   E = A % B
  149.   A = D
  150.   B = E
  151.   $5 = "Answer is:"
  152.   $6 = "Reminder is:"
  153.   GOSUB NUMBOX
  154. RETURN
  155.  
  156. ADVMATH:
  157.   DO
  158.     $T = "Advanced Maths"
  159.     $5 = "Square/Cube Number"
  160.     $6 = "Power"
  161.     $7 = "Mass Addition"
  162.     $8 = "Mass Subtraction"
  163.     $9 = "Back"
  164.     GOSUB MENUBOX
  165.     IF V = 1 THEN GOSUB SQUARE
  166.     IF V = 2 THEN GOSUB POWER
  167.     IF V = 3 THEN GOSUB MASSADD
  168.     IF V = 4 THEN GOSUB MASSTAKE
  169.   LOOP UNTIL V = 5
  170.   V = 0
  171. RETURN
  172.  
  173. SQUARE:
  174.   $T = "Square/Cube Number"
  175.   $5 = ""
  176.   $6 = "Input a number to square and cube"
  177.   V = 0
  178.   GOSUB INPBOX
  179.   A = V
  180.   D = A
  181.   A = A * D
  182.   B = A * D
  183.   $T = "Square/Cube Number"
  184.   $5 = "Number Squared is:"
  185.   $6 = "Number Cubed is:"
  186.   GOSUB NUMBOX
  187. RETURN
  188.  
  189. POWER:
  190.   $T = "Power"
  191.   $5 = "Input a number"
  192.   $6 = "Input power to raise to"
  193.   V = 0
  194.   GOSUB DINBOX
  195.   D = A
  196.   IF B = 0 THEN A = 1
  197.   IF B = 0 THEN GOTO POWERSKIP
  198.   IF B = 1 THEN GOTO POWERSKIP
  199.   DO
  200.     A = A * D
  201.     B = B - 1
  202.   LOOP UNTIL B = 1
  203.   POWERSKIP:
  204.   $T = "Power"
  205.   $5 = "Answer is:"
  206.   $6 = ""
  207.   GOSUB NUMBOX
  208. RETURN
  209.  
  210. MASSADD:
  211.   $T = "Mass Add"
  212.   $5 = "Enter the base number"
  213.   $6 = "Enter the first number to add"
  214.   V = 0
  215.   GOSUB DINBOX
  216.   N = A
  217.   N = N + B
  218. ADDMORE:
  219.   $T = "Mass Add"
  220.   $5 = "Enter another number to add"
  221.   $6 = "or zero to finish the sum"
  222.   V = 0
  223.   GOSUB INPBOX
  224.   N = N + V
  225.   IF V > 0 THEN GOTO ADDMORE
  226.   $5 = "The base number was: "
  227.   $6 = "The total was: "
  228.   B = N
  229.   GOSUB NUMBOX
  230. RETURN
  231.  
  232. MASSTAKE:
  233.   $T = "Mass Subtract"
  234.   $5 = "Enter the base number"
  235.   $6 = "Enter the first number to take"
  236.   V = 0
  237.   GOSUB DINBOX
  238.   N = A
  239.   N = N - B
  240. TAKEMORE:
  241.   $T = "Mass Subtract"
  242.   $5 = "Enter another number to take"
  243.   $6 = "or zero to finish the sum"
  244.   V = 0
  245.   GOSUB INPBOX
  246.   N = N - V
  247.   IF V > 0 THEN GOTO TAKEMORE
  248.   $5 = "The base number was: "
  249.   $6 = "The total was: "
  250.   B = N
  251.   GOSUB NUMBOX
  252. RETURN 
  253.  
  254. ABOUT:
  255.   $T = "About"
  256.   $5 = "Calculator, version 2.0.1"
  257.   $6 = "An advanced calculator application"
  258.   $7 = "Released under the GNU GPL v3"
  259.   $8 = "Written in MikeOS BASIC"
  260.   $9 = "Thanks to the MikeOS developers"
  261.   GOSUB MESBOX
  262.  
  263.   $5 = "Uses the MB++ Library, version 3.0"
  264.   $6 = "A great TUI library"
  265.   $7 = "Created by Joshua Beck"
  266.   $8 = "Mail: mikeosdeveloper@gmail.com"
  267.   $9 = "Try the new mass addition/subtraction"
  268.   GOSUB MESBOX
  269. RETURN
  270.