pragma solidity ^0.4.11; contract voteContract{ mapping (address => bool) voters; mapping (string => uint) candidates; mapping (uint8 => string) candidateList; uint8 numberOfCandidates; address contractOwner; function voteContract() public { contractOwner = msg.sender; } function addCandidate(string cand) public { bool add = true; for(uint8 i = 0; i < numberOfCandidates; i++){ if(sha3(candidateList[i]) == sha3(cand)){ add = false; break; } } if(add){ candidateList[numberOfCandidates] = cand; numberOfCandidates++; } } function vote(string cand) public { if(voters[msg.sender]){} else{ voters[msg.sender] = true; candidates[cand]++; } } function alreadyVoted() constant returns(bool){ if(voters[msg.sender]) return true; else return false; } function getNumOfCandidats() constant returns (uint8){ return numberOfCandidates; } function getScore(string cand) constant returns(uint){ return candidates[cand]; } function killContract() public { if(contractOwner == msg.sender) selfdestruct(contractOwner); } }
0.4.18