0
//SPDX-Licence-Identifier: GNU AGPL
pragma solidity >= 0.5.0 < 0.9.0;

contract Election{
    struct Candidate{
        string name;
        uint numVotes;
}
    struct Voter{
        string name;
        bool authorised;
        uint whom;
        bool voted;

    }

    address public owner;
    string public electionName;
    
    mapping (address => Voter) public voters;
    Candidate [] public candidates;
    uint public totalVotes;

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

    function startElection(string memory _electionName) public{
        owner = msg.sender;
        electionName = _electionName;
    }

    function addCandidate(string memory _candidateName) ownerOnly public{
        candidates.push(Candidate(_candidateName, 0));

    }

    function authorizeVoter(address _voterAdress) ownerOnly public{
        voters[_voterAdress] authorised = true;
    }

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

    function vote(uint candidateIndex) public{
        require(!voters[msg.sender].voted);
        require(voters[msg.sender].authorised);
        voters[msg.sender].whom = candidateIndex;
        voters[msg.sender].voted = true;
    }
 
}

error text : ParserError: Expected '{' but got 'return' function getNumCandidates() public view return(uint){ ^----^

1 Answer 1

0

you have a syntax error : in function getNumCandidates() public view returns(uint) and not return(uint) .

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.