This is my current code:
pragma solidity ^0.4.18;
contract Voting {
struct Voter {
bool voted;
address delegate;
bytes32 name;
uint weight;
uint vote;
}
mapping (bytes32 => uint8) public votesReceived;
uint[100] public people;
uint32 public counter;
bytes32[] public candidateList;
constructor(bytes32[] candidateNames) public {
candidateList = candidateNames;
people[1] = 12;
counter = 1;
}
function totalVotesFor(bytes32 candidate) view public returns (uint8) {
require(validCandidate(candidate));
return votesReceived[candidate];
}
function voteForCandidate(bytes32 candidate) view public {
require(validCandidate(candidate));
votesReceived[candidate];
}
function validCandidate(bytes32 candidate) view public returns (bool) {
for(uint i = 0; i <
candidateList.length; i++) {
if (candidateList[i] == candidate) {
return true;
}
}
return false;
}
address public chairperson;
mapping(address => Voter) public voters;
function validation(bytes32[] candidateNames) internal {
chairperson = msg.sender;
voters[chairperson].weight = 1;
}
function giveRightToVote(address voter) {
require ((msg.sender == chairperson) && !voters[voter].voted);
voters[voter].weight = 1;
}
function delegate(address to) public {
Voter sender = voters[msg.sender];
require(!sender.voted);
require(to != msg.sender);
while(voters[to].delegate != address(0)) {
to = voters[to].delegate;
require(to != msg.sender);
}
sender.voted = true;
sender.delegate = to;
Voter delegate = voters[to];
if (delegate.voted) {
candidateList[delegate.vote].voteForCandidates += sender.weight;
} else {
delegate.weight += sender.weight;
}
}
function vote(uint proposal) {
Voter sender = voters[msg.sender];
require(!sender.voted);
sender.voted = true;
sender.vote = proposal;
}
}
And the error it throws is:
/ * TypeError: Member "voteForCandidates" not found or not visible after argument-dependent lookup in bytes32 candidateList [delegate.vote] .voteForCandidates + = sender.weight; * /
^ -------------------------------------------- ^