Post by 8XenoTrogdor8 on Mar 31, 2005 1:13:16 GMT -5
I was thinking one day "Hey, I bet long division could be made into a program, and then there would be no limit to the number of decimal places!" so I made the program. I forgot exactly how the division part works otherwise I would explain it a bit (all I remember is it works like long division, (remember 5 grade? lol.)). If you find any errors, please let me know!
TextMode (TEXT_BUFFERED)
ResizeText (46, 30)
dim X, Y
dim Temp, Temp$
dim Numerator$, Denominator#
dim A#, A$, B#, B$
dim Decimal, Solution, Answer$
Start:
Cls
A# = 0
Decimal = FALSE
Solution = FALSE
Printr "Please enter two numbers to divide."
X = 0 : Y = 1
gosub Input_Only_Numbers ' InputOnlyNumbers also draws text to screen.
Numerator$ = Temp$
Printr
Printr "/ (Divided by)"
X = 0 : Y = 3
gosub Input_Only_Numbers
Denominator# = Val (Temp$)
Printr
Printr "Press Enter at any time to stop dividing"
X = 0 : Y = 6
gosub Return_Division_Digit
Printr
Printr "Divide again? (Y/N)"
DrawText ()
ClearKeys ()
While True
if KeyDown ("Y") then
goto Start
endif
if KeyDown ("N") then
goto _End_
endif
Wend
_End_:
TextMode (TEXT_SIMPLE)
Cls
Printr "What, you expected it to close? haha..."
for Temp = 0 to 350 : WaitTimer (10) : next
Printr "If you really want to leave, close the window"
for Temp = 0 to 350 : WaitTimer (10) : next
Printr "But really, now you're addicted to dividing!"
for Temp = 0 to 350 : WaitTimer (10) : next
Printr "You'll never be able to quit dividing now, "
Printr "Soon you will have divided everything! "
for Temp = 0 to 350 : WaitTimer (10) : next
Printr "And when there's nothing left to divide you "
Printr "will wander the world aimlessly, waiting..."
for Temp = 0 to 350 : WaitTimer (10) : next
Printr "And Searching..."
for Temp = 0 to 350 : WaitTimer (10) : next
Printr "To once again divide."
Print "Muaha... "
ha_loop:
Temp = 0
While Temp < 7
Temp = Temp + 1
WaitTimer (500)
if Rnd () % 2 = 1 then
Print "haha... "
else Print "ha... "
endif
Wend
for Temp = 0 to 250 : WaitTimer (10) : next
Print "(This is just going to go on and on...)"
Goto ha_loop
'-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Input_Only_Numbers:
Temp$ = ""
ClearKeys ()
While not ScanKeyDown (VK_RETURN)
Temp = InScanKey ()
if Temp >= 48 and Temp <= 57 then
Temp$ = Temp$ + Chr$ (Temp)
endif
if Temp = 8 then
Temp$ = Left$ (Temp$, (Len (Temp$) - 1))
endif
Locate X, Y
ClearLine ()
Print Temp$
DrawText ()
Wend
Return
'-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Return_Division_Digit:
' Check if user is an idiot or not
if Denominator# = 0 then
Print "Pi is exactly 3. don't divide by 0."
DrawText ()
end
endif
Answer$ = ""
ClearKeys ()
While not (ScanKeyDown (VK_RETURN) or Solution)
' Check if the numerator string is empty.
if Left$ (Numerator$, 1) = "" and not Decimal then
Decimal = TRUE
Answer$ = Answer$ + "."
else B$ = ""
endif
' Find the largest decimal place in the numerator.
A$ = Left$ (Numerator$, 1)
' The heart of the division.
A# = A# * 10 + Val (A$)
B# = Int (A# / Denominator#)
if B# = 0 and Answer$ = "" then
else
Answer$ = Answer$ + B#
endif
A# = A# - (Denominator# * B#)
' Draw digits.
Locate X, Y
ClearLine ()
Print Answer$
DrawText ()
' Reduce the numerator string by a digit.
Numerator$ = Right$ (Numerator$, Len (Numerator$) - 1)
' Check if the division is complete.
if A# = 0 and Decimal then Solution = TRUE endif
Wend
Printr
if Solution then Printr "Solution has been found" : DrawText () : endif
Return