// Function to divide two floating-point numbers represented as strings STRING PROC DivideFloatsS(STRING num1S, STRING num2S) // Declare all variables at the beginning of the function STRING intPart1S[255] = "" STRING fracPart1S[255] = "" STRING intPart2S[255] = "" STRING fracPart2S[255] = "" STRING resultS[255] = "" INTEGER dotPos1I = 0 INTEGER dotPos2I = 0 INTEGER decimalPlaces1I = 0 INTEGER decimalPlaces2I = 0 INTEGER isNegative1I = 0 INTEGER isNegative2I = 0 INTEGER isResultNegativeI = 0 STRING num1TempS[255] = num1S // Create a local copy of num1S STRING num2TempS[255] = num2S // Create a local copy of num2S STRING combined1S[255] = "" STRING combined2S[255] = "" INTEGER len1I = 0 INTEGER len2I = 0 INTEGER iI = 0 INTEGER jI = 0 INTEGER remainderI = 0 INTEGER quotientI = 0 INTEGER tempI = 0 INTEGER precisionI = 10 // Number of decimal places in the result STRING tempResultS[255] = "" INTEGER dotPosI = 0 INTEGER divisorI = 0 INTEGER dividendI = 0 INTEGER resultLenI = 0 // Determine if the numbers are negative IF SubStr(num1TempS, 1, 1) == "-" isNegative1I = 1 num1TempS = SubStr(num1TempS, 2, Length(num1TempS) - 1) // Remove the negative sign ENDIF IF SubStr(num2TempS, 1, 1) == "-" isNegative2I = 1 num2TempS = SubStr(num2TempS, 2, Length(num2TempS) - 1) // Remove the negative sign ENDIF // Determine the sign of the result // XOR equivalent: (isNegative1I AND NOT isNegative2I) OR (NOT isNegative1I AND isNegative2I) isResultNegativeI = (isNegative1I AND NOT isNegative2I) OR (NOT isNegative1I AND isNegative2I) // Split the input numbers into integer and fractional parts dotPos1I = Pos(".", num1TempS) dotPos2I = Pos(".", num2TempS) IF dotPos1I > 0 intPart1S = SubStr(num1TempS, 1, dotPos1I - 1) fracPart1S = SubStr(num1TempS, dotPos1I + 1, Length(num1TempS) - dotPos1I) ELSE intPart1S = num1TempS fracPart1S = "0" ENDIF IF dotPos2I > 0 intPart2S = SubStr(num2TempS, 1, dotPos2I - 1) fracPart2S = SubStr(num2TempS, dotPos2I + 1, Length(num2TempS) - dotPos2I) ELSE intPart2S = num2TempS fracPart2S = "0" ENDIF // Remove leading zeros from integer parts WHILE SubStr(intPart1S, 1, 1) == "0" AND Length(intPart1S) > 1 intPart1S = SubStr(intPart1S, 2, Length(intPart1S) - 1) ENDWHILE WHILE SubStr(intPart2S, 1, 1) == "0" AND Length(intPart2S) > 1 intPart2S = SubStr(intPart2S, 2, Length(intPart2S) - 1) ENDWHILE // Remove trailing zeros from fractional parts WHILE SubStr(fracPart1S, Length(fracPart1S), 1) == "0" AND Length(fracPart1S) > 1 fracPart1S = SubStr(fracPart1S, 1, Length(fracPart1S) - 1) ENDWHILE WHILE SubStr(fracPart2S, Length(fracPart2S), 1) == "0" AND Length(fracPart2S) > 1 fracPart2S = SubStr(fracPart2S, 1, Length(fracPart2S) - 1) ENDWHILE // Combine integer and fractional parts into single strings combined1S = intPart1S + fracPart1S combined2S = intPart2S + fracPart2S // Calculate the number of decimal places decimalPlaces1I = Length(fracPart1S) decimalPlaces2I = Length(fracPart2S) // Pad the shorter number with zeros to make lengths equal IF decimalPlaces1I > decimalPlaces2I FOR iI = 1 TO (decimalPlaces1I - decimalPlaces2I) combined2S = combined2S + "0" ENDFOR ELSEIF decimalPlaces2I > decimalPlaces1I FOR iI = 1 TO (decimalPlaces2I - decimalPlaces1I) combined1S = combined1S + "0" ENDFOR ENDIF // Convert combined strings to integers dividendI = Val(combined1S) divisorI = Val(combined2S) // Handle division by zero IF divisorI == 0 Warn("Error: Division by zero.") RETURN("0") ENDIF // Perform division quotientI = dividendI / divisorI remainderI = dividendI MOD divisorI // Convert the quotient to a string resultS = Str(quotientI) // Handle the fractional part IF remainderI > 0 resultS = resultS + "." FOR iI = 1 TO precisionI remainderI = remainderI * 10 quotientI = remainderI / divisorI resultS = resultS + Str(quotientI) remainderI = remainderI MOD divisorI ENDFOR ENDIF // Remove trailing zeros after the decimal point dotPosI = Pos(".", resultS) IF dotPosI > 0 WHILE SubStr(resultS, Length(resultS), 1) == "0" resultS = SubStr(resultS, 1, Length(resultS) - 1) ENDWHILE IF SubStr(resultS, Length(resultS), 1) == "." resultS = SubStr(resultS, 1, Length(resultS) - 1) ENDIF ENDIF // Add the negative sign if the result is negative IF isResultNegativeI resultS = "-" + resultS ENDIF RETURN(resultS) END // Main function to test the division PROC Main() STRING num1S[255] = "" STRING num2S[255] = "" STRING resultS[255] = "" // Ask the user for the first number IF Ask("Enter the first number: ", num1S) // Ask the user for the second number IF Ask("Enter the second number: ", num2S) // Perform the division and display the result resultS = DivideFloatsS(num1S, num2S) Warn("Result: ", resultS) CopyToWinClip( resultS ) ELSE Warn("Second number input was canceled.") ENDIF ELSE Warn("First number input was canceled.") ENDIF END