Created
November 8, 2019 16:25
-
-
Save ernestognw/d43b0b0b069c4b615fffd72212d32c41 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
pragma solidity ^0.5.11; | |
contract Calculadora { | |
// Variables | |
uint256 public res; | |
uint256 limit; // Limit será el máximo entero que puede representar la calculadora | |
// Constructor | |
constructor() public { | |
res = 0; | |
limit = 115792089237316195423570985008687907853269984665640564039457584007913129639935; | |
} | |
// Metodos | |
// function function_name([args]) [visibility] [mutability] [returns([type])] [modifiers] {} | |
// Suma | |
function add(uint256 toSum) public returns(uint256) { | |
require(res + toSum != limit, "Overflow!!"); | |
res += toSum; | |
return res; | |
} | |
// Resta | |
function substract(uint256 toSubstract) public returns(uint256) { | |
require(res - toSubstract != limit, "Overflow!!"); | |
res -= toSubstract; | |
return res; | |
} | |
// Multiplicación | |
function multiply(uint256 toMultiply) public returns(uint256){ | |
require(res * toMultiply != limit, "Overflow!!"); | |
res *= toMultiply; | |
return res; | |
} | |
// División | |
function division(uint256 toDivide) public returns(uint256){ | |
require(res / toDivide != limit, "Overflow!!"); | |
res /= toDivide; | |
return res; | |
} | |
// Reset | |
function reset() public { | |
res = 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment