accept fractions
This commit is contained in:
parent
8ebea26bdd
commit
5c954b63b1
|
@ -1,4 +1,4 @@
|
||||||
import strutils, sequtils, terminal
|
import strutils, sequtils, terminal, re
|
||||||
|
|
||||||
#? validate if user input is of correct type
|
#? validate if user input is of correct type
|
||||||
proc getInt: int =
|
proc getInt: int =
|
||||||
|
@ -12,7 +12,15 @@ proc getInt: int =
|
||||||
proc getFloat: float =
|
proc getFloat: float =
|
||||||
while(true):
|
while(true):
|
||||||
try:
|
try:
|
||||||
return parseFloat(readline(stdin))
|
let number: string = readline(stdin).replace(" ","").replace("\t", "")
|
||||||
|
|
||||||
|
#? if the number given is a fraction convert it into decimal
|
||||||
|
if match(number, re"[0-9]+/[0-9]+"):
|
||||||
|
let
|
||||||
|
numerator: float = number.split('/')[0].parseFloat
|
||||||
|
denominator: float = number.split('/')[1].parseFloat
|
||||||
|
return numerator / denominator
|
||||||
|
return parseFloat(number)
|
||||||
except:
|
except:
|
||||||
styledEcho resetStyle, "Please enter a ", styleBright, "number, " , resetStyle, "try again."
|
styledEcho resetStyle, "Please enter a ", styleBright, "number, " , resetStyle, "try again."
|
||||||
|
|
||||||
|
@ -167,5 +175,7 @@ proc scalar* =
|
||||||
|
|
||||||
let M = calcScalar(f, m)
|
let M = calcScalar(f, m)
|
||||||
|
|
||||||
echo "\nResult matrix is:"
|
echo "\nInitial matrix is:"
|
||||||
|
printMatrix(m)
|
||||||
|
echo "\nScaled matrix is:"
|
||||||
printMatrix(M)
|
printMatrix(M)
|
Loading…
Reference in a new issue