struct 는 다양한 데이터 타입을 넣을 수 있는 구조체
독립적으로는 잘 사용하지 않음
struct 를 만들고 리스트에 값을 넣어서 사용
더보기
pragma solidity 0.8.0;
contract Last_days_of_April {
struct student {
string name;
uint year;
uint month;
uint day;
uint score;
}
student[] students;
function setStudent(string memory _name, uint _year, uint _month, uint _day, uint _score) public {
students.push(student(_name, _year, _month, _day, _score));
}
function getAverage() public view returns(uint) {
uint a = 0;
for(uint i = 0; i<students.length; i++){
a += students[i].score;
}
return a/students.length;
}
}
'Blockchain' 카테고리의 다른 글
(1) Truffle :: DApp 개발환경 구성하기 (windows) _ 설치 (0) | 2021.05.15 |
---|---|
remix 에서 MetaMask 연결안됨 (0) | 2021.05.15 |
solidity 에서 array 사용한 코드 (0) | 2021.04.30 |
remix 에서 작성한 solidity 코드 배포하기 (0) | 2021.04.30 |
remix 에서 solidity add 함수 작성하기 (0) | 2021.04.26 |