-
Notifications
You must be signed in to change notification settings - Fork 0
/
simpleMath.sol
58 lines (49 loc) · 1.85 KB
/
simpleMath.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.4.16 <0.9.0;
//contact : [email protected]
//crypto wallet : Fettah@crypto
// this simple contract build one simple storage contract
// https://github.com/mhd-fettah/Solidity-simple-contracts/blob/main/simpleStorage.sol
// to do simple math .
contract SimpleMath {
uint firstNumber;
uint SecondNumber;
uint latestResult;
string latestOpration;
function set(uint VarfirstNumber,uint VarSecondNumber) public {
firstNumber = VarfirstNumber;
SecondNumber = VarSecondNumber;
}
function checkNumbers() public view returns (uint,uint) {
return (firstNumber,SecondNumber);
}
function checklatestOpration() public view returns (string memory) {
return (latestOpration);
}
function checklatestResult() public view returns (uint) {
return (latestResult);
}
/// use one of oprations . { sum , minus , multiple , divide }
function math(string memory opration) public returns(bool,uint){
if (keccak256(bytes(opration))==keccak256(bytes('sum'))){
latestResult = firstNumber + SecondNumber;
}
else if (keccak256(bytes(opration))==keccak256(bytes('minus'))){
latestResult = firstNumber - SecondNumber;
}
else if (keccak256(bytes(opration))==keccak256(bytes('multiple'))){
latestResult = firstNumber * SecondNumber;
}
else if (keccak256(bytes(opration))==keccak256(bytes('divide'))){
latestResult = firstNumber / SecondNumber;
}
else {
/// your opration name is not recognized
return (false,0);
}
latestOpration = opration;
return (true,latestResult);
}
}
//contact : [email protected]
//crypto wallet : Fettah@crypto