-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e487529
commit 467bf22
Showing
2 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
using CLIcalc | ||
|
||
CLIcalc.julia_main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
module CLIcalc | ||
function main() | ||
println("Hi, what function would you like to use? (mul, sub, add, div, exit)") | ||
func = readline() | ||
if (func == "add") | ||
print("x: ") | ||
a = readline(keep=false) | ||
print("y: ") | ||
b = readline(keep=false) | ||
x = parse(Int64, a) | ||
y = parse(Int64, b) | ||
add(x, y) = x + y | ||
z = add(x, y) | ||
println("result: $z") | ||
elseif (func == "sub") | ||
print("x: ") | ||
a = readline(keep=false) | ||
print("y: ") | ||
b = readline(keep=false) | ||
x = parse(Int64, a) | ||
y = parse(Int64, b) | ||
subtract(x, y) = x - y | ||
z = subtract(x, y) | ||
println("result: $z") | ||
elseif (func == "div") | ||
println("x: ") | ||
a = readline(keep=false) | ||
println("y: ") | ||
b = readline(keep=false) | ||
x = parse(Int64, a) | ||
y = parse(Int64, b) | ||
divide(x, y) = x / y | ||
z = divide(x, y) | ||
println("result: $z") | ||
elseif (func == "mul") | ||
print("x: ") | ||
a = readline(keep=false) | ||
print("y: ") | ||
b = readline(keep=false) | ||
x = parse(Int64, a) | ||
y = parse(Int64, b) | ||
mul(x, y) = x * y | ||
z = mul(x, y) | ||
println("result: $z") | ||
elseif (func == "exit") | ||
Base.exit() | ||
else | ||
println("Function not found. Exiting with error code 1") | ||
Base.exit() | ||
end | ||
|
||
end | ||
|
||
function julia_main() | ||
while true | ||
main() | ||
end | ||
return 0 | ||
end | ||
end |