본문 바로가기
Blockchain

remix solidity struct 사용 코드

by 마티 2021. 4. 30.

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;

  }

}