0

I got the above error at the mapping 'candidate'

pragma solidity ^0.4.22;

contract Election {
  struct Candidates {
    string name;
    uint voteCount;
  }

  struct voter {
    bool authorized;
    bool voted;
    uint vote;
  }

  address public owner;
  string public electionName;

  mapping(address => voter) public voters;
  Candidate[] public candidates; 
  uint public totalVotes;

  modifier ownerOnly() {
    require(msg.sender == owner);

    _;
  }

  function electionName(string _name) public {
    owner = msg.sender;
    electionName = _name;
  }

  function addCandidate(string _name) ownerOnly public {
    candidates.push(Candidate(_name, 0));
  }

  function getNumCandidate() public view returns(uint) {
    return candidates. length;
  }

  function authorize( address _person) ownerOnly public{
    voters[_person].authorized = true;
  }

  function vote(uint voteIndex) public {
    require(!voters[msg.sender].voted);
    require(voters[msg.sender].authorized);

    voters[msg.sender].voted = true;
    voters[msg.sender].voteIndex = _voteIndex;

    candidates[_voteIndex].voteCount += 1;
    selfdestruct(owner);
  }
}

Error

browser/Election.sol:22:5: DeclarationError: Identifier not found or not unique.
    Candidate[] public candidates; 
    ^-------^
Mikhail Vladimirov
  • 7,313
  • 1
  • 23
  • 38
chuks
  • 1
  • 1

1 Answers1

1

You should refer to struct when defining an array. So in your case you are referring to struct candidate instead of Candidates which you declared. So use

Candidates[] public candidates

Salman Dev
  • 105
  • 1
  • 7