-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbmi_calc.sol
64 lines (49 loc) · 1.48 KB
/
bmi_calc.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
59
60
61
62
//SPDX-License-Identifier:MIT
pragma solidity 0.8.13;
contract BMI_CALC {
//Enum for different range of BMI
enum bmi_status {
underweight,
normal,
overweight,
obese
}
//Used state variables
uint8 public bodymassindex;
bmi_status public weight_status;
address owner;
//contructor to initialize state variable 'owner' to the account that calls the contract
constructor () {
owner = msg.sender;
}
//Modifier - only contract deployer can call some functions
modifier OnlyOwner() {
require(msg.sender == owner, "Only owner can call");
_;
}
//Event for when BMI is calculated
event BMIcalculated (
address owner,
uint date
);
//Calculate BMI
function getBMI(uint8 height,uint8 weight) public OnlyOwner{
bodymassindex = height/weight;
emit BMIcalculated(msg.sender, block.timestamp);
}
//Get weight status from BMI
function checkBmiStatus(uint8 _bodymassindex) public OnlyOwner {
if (_bodymassindex <= 18) {
weight_status = bmi_status.underweight;
}
else if (_bodymassindex >= 19 && _bodymassindex <= 25){
weight_status = bmi_status.normal;
}
else if (_bodymassindex >= 26 && _bodymassindex <= 30){
weight_status = bmi_status.overweight;
}
else if (_bodymassindex > 30){
weight_status = bmi_status.obese;
}
}
}