From 4d3a8c5b6c13659cdac8896ea0cc571cf2e8e9dd Mon Sep 17 00:00:00 2001 From: Jaka Potokar Date: Sun, 15 Oct 2023 17:23:55 +0200 Subject: [PATCH 1/3] Added a calculator contract --- Calculator_Contract.sol | 52 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 Calculator_Contract.sol diff --git a/Calculator_Contract.sol b/Calculator_Contract.sol new file mode 100644 index 0000000..93e680a --- /dev/null +++ b/Calculator_Contract.sol @@ -0,0 +1,52 @@ +# Calculator!" smart contract written in Solidity, which is a popular programming language for creating Ethereum smart contracts: + +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +/** + * @title Calculator + * @dev A simple smart contract for performing basic arithmetic operations. + */ +contract Calculator { + /** + * @dev Adds two numbers and returns the result. + * @param a The first number. + * @param b The second number. + * @return The sum of a and b. + */ + function add(uint256 a, uint256 b) public pure returns (uint256) { + return a + b; + } + + /** + * @dev Subtracts two numbers and returns the result. + * @param a The first number. + * @param b The second number. + * @return The difference between a and b. + */ + function subtract(uint256 a, uint256 b) public pure returns (uint256) { + require(a >= b, "Subtraction underflow"); + return a - b; + } + + /** + * @dev Multiplies two numbers and returns the result. + * @param a The first number. + * @param b The second number. + * @return The product of a and b. + */ + function multiply(uint256 a, uint256 b) public pure returns (uint256) { + return a * b; + } + + /** + * @dev Divides two numbers and returns the result. + * @param a The numerator. + * @param b The denominator. + * @return The result of a divided by b. + */ + function divide(uint256 a, uint256 b) public pure returns (uint256) { + require(b != 0, "Division by zero"); + return a / b; + } +} From 480798decc2b7c380322595fc8ea12733680cb86 Mon Sep 17 00:00:00 2001 From: Jaka Potokar Date: Sun, 15 Oct 2023 17:38:01 +0200 Subject: [PATCH 2/3] Added a calculator contract --- Calculator_Contract.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Calculator_Contract.sol b/Calculator_Contract.sol index 93e680a..f078815 100644 --- a/Calculator_Contract.sol +++ b/Calculator_Contract.sol @@ -1,4 +1,4 @@ -# Calculator!" smart contract written in Solidity, which is a popular programming language for creating Ethereum smart contracts: +// Calculator!" smart contract written in Solidity, which is a popular programming language for creating Ethereum smart contracts: // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; From 14e412c949e56a96681fe276d10b10dc8711b385 Mon Sep 17 00:00:00 2001 From: Jaka Potokar Date: Sun, 15 Oct 2023 17:39:08 +0200 Subject: [PATCH 3/3] Added a calculator contract --- Calculator_Contract.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Calculator_Contract.sol b/Calculator_Contract.sol index f078815..9a22154 100644 --- a/Calculator_Contract.sol +++ b/Calculator_Contract.sol @@ -1,4 +1,4 @@ -// Calculator!" smart contract written in Solidity, which is a popular programming language for creating Ethereum smart contracts: +// Calculator! Smart contract written in Solidity, which is a popular programming language for creating Ethereum smart contracts: // SPDX-License-Identifier: MIT pragma solidity ^0.8.0;