sanitization
This commit is contained in:
parent
c7e4ffb07d
commit
81f6ada779
22
src/main.nim
22
src/main.nim
|
@ -1,8 +1,7 @@
|
||||||
import strutils, sequtils, os, procedures, strformat
|
import strutils, sequtils, os, procedures
|
||||||
# TODO: while loop to check if inputs are valid
|
|
||||||
|
|
||||||
var operation: string
|
var operation: string
|
||||||
# if command is "dot" or "cross" preform that operation
|
#? if command is "dot" or "cross" preform that operation
|
||||||
if paramStr(0).endsWith("/dot") or paramStr(0) == "dot":
|
if paramStr(0).endsWith("/dot") or paramStr(0) == "dot":
|
||||||
operation = "dot"
|
operation = "dot"
|
||||||
echo "Calculating the dot product:"
|
echo "Calculating the dot product:"
|
||||||
|
@ -11,9 +10,16 @@ elif paramStr(0).endsWith("/cross") or paramStr(0) == "cross":
|
||||||
echo "Calculating the cross product:"
|
echo "Calculating the cross product:"
|
||||||
else:
|
else:
|
||||||
echo "Would you like to preform the dot or cross product?"
|
echo "Would you like to preform the dot or cross product?"
|
||||||
operation = readLine(stdin)
|
operation = toLowerAscii(readLine(stdin))
|
||||||
|
case operation:
|
||||||
|
of "dot":
|
||||||
|
operation = "dot"
|
||||||
|
of "cross":
|
||||||
|
operation = "cross"
|
||||||
|
else:
|
||||||
|
quit "Invalid matrix operation!", QuitFailure
|
||||||
|
|
||||||
# record first matrix
|
#? record first matrix
|
||||||
echo "Enter number of rows in the first matrix:"
|
echo "Enter number of rows in the first matrix:"
|
||||||
let r1: int = parseInt(readLine(stdin))
|
let r1: int = parseInt(readLine(stdin))
|
||||||
echo "Enter number of columns in the first matrix:"
|
echo "Enter number of columns in the first matrix:"
|
||||||
|
@ -23,7 +29,7 @@ procedures.fillMatrix(m1, r1, c1)
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
# record second matrix
|
#? record second matrix
|
||||||
echo "Enter number of rows in the second matrix:"
|
echo "Enter number of rows in the second matrix:"
|
||||||
let r2: int = parseInt(readLine(stdin))
|
let r2: int = parseInt(readLine(stdin))
|
||||||
echo "Enter number of columns in the second matrix:"
|
echo "Enter number of columns in the second matrix:"
|
||||||
|
@ -31,12 +37,12 @@ let c2: int = parseInt(readLine(stdin))
|
||||||
var m2 = newSeqWith(r2, newSeq[float](c2))
|
var m2 = newSeqWith(r2, newSeq[float](c2))
|
||||||
procedures.fillMatrix(m2, r2, c2)
|
procedures.fillMatrix(m2, r2, c2)
|
||||||
|
|
||||||
# resultent matrix
|
#? resultent matrix
|
||||||
var m = newSeqWith(0, newSeq[float](0))
|
var m = newSeqWith(0, newSeq[float](0))
|
||||||
|
|
||||||
case operation:
|
case operation:
|
||||||
of "dot":
|
of "dot":
|
||||||
m = dot(m1, m2) # calculate dot product (in procedures)
|
m = dot(m1, m2) #? calculate dot product (in procedures)
|
||||||
of "cross":
|
of "cross":
|
||||||
echo "*do cross product*" # TODO: calculate cross product (in procedures)
|
echo "*do cross product*" # TODO: calculate cross product (in procedures)
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue