这篇博客作为记录学习solidity语言的备忘录
pragma solidity ^0.4.0;
//尝试写一个关于投票的智能合约;
//投票人每人只有一票;
//候选人票数多获胜,若平票则再投一轮;
//候选人不能参与投票;
contract Votegame{
struct voter{
address vaddr;//投票人地址
bool yn;//是否投票
uint amount;//票数
}
struct candidate{
address caddr;//候选人地址
uint get;//得到的票数
bool win;//是否获胜
}
address chairperson;
mapping(address => voter) voters;
mapping(address => candidate) candidates;
function candidater1(address Candidate1){
// 候选人初始化
candidates[Candidate1].get = 0;
candidates[Candidate1].win = false;
}
/*function candidater2(address Candidate2){
// initialize
candidates[Candidate2].get = 0;
candidates[Candidate2].win = false;
}*/
//投票人初始化
function giveRightToVote(address Voter) {
if (msg.sender != chairperson || voters[Vot