简体   繁体   中英

Solidity code that allows someone to input their yearly salary and get financial advice. I can't input salary and get result based on the input

// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.8.0 <0.9.0;
contract Artithmetic{

    uint256  yearlySalary = 250000 ;
    uint256  months = 12;
    uint256 conversionRate = 113;
    uint256 public  monthlySalary = yearlySalary / months * conversionRate;
    string public message = "Import a 2021 Audi A6";
    bool public youreRich = true;

    function updateYearlySalary(uint256 _yearlySalary) public{
        
        yearlySalary = _yearlySalary;
        
    }
    

    function financialAdvice() public {

        if(monthlySalary<=2000000){
            
            youreRich = false;
            message = "Buy assets that earn you passive income first!";
        }

    }}

I can't get the code to perform arithmetic that would change the financial advice based on the amount I input when I compile.

You should write an additional function to set the monthly salary

uint256 public  monthlySalary;

function setMonthlySalary() public {
    monthlySalary= yearlySalary / months * conversionRate;
}

Update yearly salary first. call updateYearlySalary

then call setMonthlySalary

then call financialAdvice

Finally call message and it will be updated:

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM