Skip to main content
3 of 7
added 4 characters in body

when writing a simple voting smart contract, it gives an error :

    //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;
}

}

error text : Election.sol:9:5: ParserError: Expected pragma, import directive or contract/interface/library definition. struct Voter{ ^----^