Making a Calculator
Below is a video instruction on how to create a Calculator using Trillium!
In this example you will be creating a calculator program that will accept two types of int (firstNum and secondNum) as well as an operator type and it will return a type of string.
Step 1: Create the function
Below you will create the function for your calculator program
In this example you have created a function called calculator. This function accepts a type 'int' and is called 'firstNum'. The secondNum is the same and the operator is of type 'string'. It will also return a type of string which is indicated at the end of the closed parenthesis ') : string'
Step 2: Create the conditional statements for operator types
Below you are going to create the conditional statements for the support operator types of '+', '-', '*', '/'. You will also create a function to return our result like in the helloWorld example. This will be called 'result'.
In this example you have created a function called calculator. This function accepts a type 'int' and is called 'firstNum' and 'secondNum'. It will also return a type of string which is indicated at the end of the closed parenthesis ') : string'. This function also now stores the result that is passed into it into the variable 'result'.
Step 3: Do Arithmetic and Return Result
Below you are taking all the variables passed in and performing the correct arithmetic operation on them based on the operator passed in. If no known operator is passed it will return the message 'No known operator was given'.
Congrats! You have created your first calculator with Trillium! Below is a video that will walk you through all of this in case you are stuck at any points.