Learning Nim - 4
Creating a simple Risk management calculation app
Let's create a simple app that calculates SLE (single loss expectancy) and ARO (Annual rate of occurrence)
Showing the full code:
import std/[strutils,strformat,linenoise,math] # here we import our libraries or modules we want to use. echo "Quantative Risk Analysis","\n" # Ask user for input to calculate SLE echo "Calculate Single Loss Expectancy","\n" echo "Enter Asset Value (as int 1..n) ","\n" let asset = readLine(stdin).parseInt() echo "Enter Exposure Factor as float 0.0..n) " let ef = readLine(stdin).parseFloat() clearScreen() echo "Calculate Annual Rate of Occurence","\n" echo "Enter ARO as float: " let aro = readLine(stdin).parseFloat() clearScreen() # Calculate asset value * exposure factor proc calculateSLE(asset: int, ef: float): float = return asset.float * ef proc calculateALE(sle: float, aro: float): float = return sle * aro # store var calculation in sle variable let sle = calculateSLE(asset, ef) let ale = calculateALE(sle, aro) echo "SLE is: ", fmt"{sle}", " ", "ARO is: ", fmt"{ale}"
Example running the compiled code: