Skip to content

ovijitM/voting-with-blockchain

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract voting{
    mapping(address=>bool) public voted;
    uint public p1vote;
    uint public p2vote;
    uint public p3vote;

    modifier samecode(){
        require(!voted[msg.sender],"you already voted");
        voted[msg.sender]=true;
        _;
    }

    function p1() public samecode{
        p1vote+=1;
    }
    function p2() public samecode{
        p2vote+=1;
    }
    function p3() public samecode{
        p3vote+=1;
    }

    function winner() public view returns(string memory){
        uint maxvotetake=p1vote;
        if(maxvotetake>p2vote){
            p1vote==maxvotetake;
            return "p1 is winner";
        }
        if (maxvotetake>p3vote){
            maxvotetake=p2vote;
            return "p2 is winner";
        }
        else return "p3 is winner";
        
    }

}

About

create a contract which taking vote and show winner

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published