1

screenshot of my errori am trying to create e platform which people can contribute in answering questions by sending funds with specific answer to a question: group A or B, can anyone help me why am i getting this error?

pragma solidity ^0.8.2;

contract prediction {

address private Manager;

string public Question;

string public winnerGroup;

mapping(address => string) userGroup;

mapping(address => uint) payment;

//mapping(address => uint) profitPerUser;


constructor(string memory _Question) {
    Manager == msg.sender;
    Question = _Question;
}


modifier onlyManager() {
    require(msg.sender == Manager);
    _;
}

struct group_A {
    address[] addresses;
    uint totalFund;
    uint userCount;
    uint profitPerUser;
}

struct group_B {
    address[] addresses;
    uint totalFund;
    uint userCount;
    uint profitPerUser;
}







function pickAnswerA() public payable {
    group_A.addresses.push(msg.sender);
    payment[msg.sender] += msg.value;
    group_A.totalFund = msg.value;
    group_A.userCount += 1;
    userGroup[msg.sender] == "A";
}

function pickAnswerB() public payable {
    group_B.addresses.push(msg.sender);
    payment[msg.sender] += msg.value;
    group_B.totalFund += msg.value;
    group_B.userCount += 1;
    userGroup[msg.sender] == "B";
}
1

You are mixing up the equality operator (==) and the assignment operator (=) in several places.

For example:

  • Manager == msg.sender; should be Manager = msg.sender;
  • userGroup[msg.sender] == "A"; should be userGroup[msg.sender] = "A";
  • userGroup[msg.sender] == "B"; should be userGroup[msg.sender] = "B";

(There might be other things - I haven't actually compiled the code.)

2
  • Thanks.I didn't know that issue,But i am getting the same error again :( – Sina Rahimi Mar 20 at 20:44
  • Okay, I've had a closer look. You have declared the types group_A and group_B, but you haven't actually declared variables for those types. You need to declare a global variable for each one, and then .push() onto those variables. e.g. group_A A_variable; and A_variable.addresses.push(msg_sender); – Richard Horrocks Mar 20 at 20:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.