solidity加減乘除 === //SPDX-License-Identifier: MIT //版本要大於0.8.11 pragma solidity ^ 0.8.11; //契約名稱叫做practice contract practice{ int public answer = 10; function Operator(string memory operation) public { if(keccak256(abi.encodePacked(operation)) ==keccak256(abi.encodePacked("add"))) { answer+=1; //若是輸入的字元跟ADD比較,相同就把answer+1; } if(keccak256(abi.encodePacked(operation)) ==keccak256(abi.encodePacked("sub"))) { answer-=1;//把輸入的字元跟sub比較,相同就是-1 } } function answer_double() view public returns(uint256) { return uint256(answer)*2; //把answer的數值乘以2 } }
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up