简体   繁体   English

允许某人输入他们的年薪并获得财务建议的 Solidity 代码。 我无法输入薪水并根据输入获得结果

[英]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你应该额外写一个 function 来设置月薪

uint256 public  monthlySalary;

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

Update yearly salary first.先更新年薪。 call updateYearlySalary致电updateYearlySalary

then call setMonthlySalary然后调用setMonthlySalary

then call financialAdvice然后致电financialAdvice

Finally call message and it will be updated:最后调用message ,它将被更新:

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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