I am trying to make a voting system and I have come up with something but at the moment the vote count is not increasing. Can you check what is wrong? I am beginner and my code is below.
Contract Code
struct Candidate {
uint64 votes;
string name;
mapping(address => uint) voteMapping;
bool flag;
address add;
}
struct Team {
Candidate[] candidates;
mapping(uint => Candidate) candidateMapping;
mapping(address => bool) addressMap;
string name;
uint[] cidArr;
uint token;
address creator;
bool flag;
}
//More code in between
function vote(uint tCid, uint cid) external {
Team storage t = getTeam(tCid);
if (t.flag) {
Candidate storage c = t.candidateMapping[cid];
if (
c.flag && c.voteMapping[msg.sender] == 0 && t.addressMap[msg.sender]
) {
c.voteMapping[msg.sender] = 1;
c.votes++;
emit VoteDone(true);
}
}
emit VoteDone(false);
}
function getCandidateVotes(
uint tCid,
uint cid
) external view returns (uint256) {
Team storage t = getTeam(tCid);
Candidate storage c = t.candidateMapping[cid];
return c.votes;
}
Whenever I call the getCandidateVotes method, I have always received 1 even after voting multiple times. Can you help me fix this?