//Write your own contracts here. Currently compiles using solc v0.4.15+commit.bbb8e64f. pragma solidity ^0.4.26; contract Ballot { struct Voter{ uint weight; bool voted; uint8 vote; } struct Proposal{ uint voteCount; } enum Stage(Init,Reg,) address chairperson; Proposal[] proposals; mapping(address => Voter) voters; constructor(uint8 _numProposals) public{ chairperson = msg.sender; proposals.length = _numProposals; voters[chairperson].weight = 2; } function giveRightToVote(address voter) external { require( msg.sender == chairperson,"non sei il chairperson dioporco" ); require( !voters[voter].voted,"il votatore ha gia votato, dioporco" ); require(voters[voter].weight == 0); voters[voter].weight = 1; } function vote(uint8 proposal) external { Voter storage sender = voters[msg.sender]; require(sender.weight != 0,"non hai diritto a votare, dioporco"); require(!sender.voted,"hai gia votato dioporco"); sender.voted = true; sender.vote = proposal; // If `proposal` is out of the range of the array, // this will throw automatically and revert all // changes. proposals[proposal].voteCount += sender.weight; } function winningProposal() public view returns (uint winningProposal_) { uint winningVoteCount = 0; for (uint p = 0; p < proposals.length; p++) { if (proposals[p].voteCount > winningVoteCount) { winningVoteCount = proposals[p].voteCount; winningProposal_ = p; } } } }
0.4.26