Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#,在表单中实现单选按钮以计算嵌套鸡蛋_C#_Winforms_C# 4.0_C# 3.0 - Fatal编程技术网

C#,在表单中实现单选按钮以计算嵌套鸡蛋

C#,在表单中实现单选按钮以计算嵌套鸡蛋,c#,winforms,c#-4.0,c#-3.0,C#,Winforms,C# 4.0,C# 3.0,我一直在研究一个问题,我想做一个简单的计算。我对C#相当陌生,但我正在努力学习 基本上,考虑到四种不同的输入:期望收入、税率、估计回报率和每个时间段的收入,我需要存多少钱 我使用一组单选按钮来选择每个时间段的收入,基本上是每天、每周、每月、每年的收入。因此,单选按钮选择如何将收入列为一个值,但我不确定如何将此部分的变量输入计算部分。我将提供一个代码片段 任何帮助都将不胜感激,谢谢 private void radioButton2_CheckedChanged(object sender,

我一直在研究一个问题,我想做一个简单的计算。我对C#相当陌生,但我正在努力学习

基本上,考虑到四种不同的输入:期望收入、税率、估计回报率和每个时间段的收入,我需要存多少钱

我使用一组单选按钮来选择每个时间段的收入,基本上是每天、每周、每月、每年的收入。因此,单选按钮选择如何将收入列为一个值,但我不确定如何将此部分的变量输入计算部分。我将提供一个代码片段

任何帮助都将不胜感激,谢谢

   private void radioButton2_CheckedChanged(object sender, EventArgs e)
    {
        // Local variables
        decimal income;
        // Get the income, tax rate and rate of return.
        income = decimal.Parse(incomeDesiredTextBox.Text);

        // Determine pay period
        if (true)
        {
            if (incomePerDayRadioButton.Checked)
            {
                decimal newIncome = income / 365;
                return;
            }
            else if (incomePerMonthRadioButton.Checked)
            {
                decimal newIncome = income / 24;
                return;
            }
            else if (incomePerWeekRadioButton.Checked)
            {
                decimal newIncome = income / 52;
                return;
            }
            else if (incomePerYearRadioButton.Checked)
            {
                decimal newIncome = income / 1;
                return;
            }
        }
    }

    private void calculateButton_Click(object sender, EventArgs e)
    {
        // Local variables
        decimal income;
        decimal newIncome;
        decimal taxRate;
        decimal rateOfReturn;

        // Get the income, tax rate and rate of return.
        income = decimal.Parse(incomeDesiredTextBox.Text);
        taxRate = decimal.Parse(totalTaxesTextBox.Text);
        rateOfReturn = decimal.Parse(rateOfReturnTextBox.Text);


        //change rate of return to decimal format
        var rateOfReturnPercentage = rateOfReturn / 100;

        // Calculate Nest Egg.
        decimal taxedIncome = newIncome * taxRate;



    }

您应该创建一个单独的方法来计算新收入

public decimal CalculateNewIncome()
{
        decimal income;
        // Get the income, tax rate and rate of return.
        income = decimal.Parse(incomeDesiredTextBox.Text);

        if (incomePerDayRadioButton.Checked)
        {
            return income / 365;
        }
        else if (incomePerMonthRadioButton.Checked)
        {
            return income / 24; // should be 30 ?
        }
        else if (incomePerWeekRadioButton.Checked)
        {
            return income / 52;
        }
        else if (incomePerYearRadioButton.Checked)
        {
            return income;
        }
}
然后你可以做如下计算

private void calculateButton_Click(object sender, EventArgs e)
{
    // Local variables
    decimal income;
    decimal newIncome = CalculateNewIncome();
    decimal taxRate;
    decimal rateOfReturn;

    // Get the income, tax rate and rate of return.
    income = decimal.Parse(incomeDesiredTextBox.Text);
    taxRate = decimal.Parse(totalTaxesTextBox.Text);
    rateOfReturn = decimal.Parse(rateOfReturnTextBox.Text);


    //change rate of return to decimal format
    var rateOfReturnPercentage = rateOfReturn / 100;

    // Calculate Nest Egg.
    decimal taxedIncome = newIncome * taxRate;

    // display it
}

!.我已经包括了一个到Gyazo的链接,这个表单到目前为止是什么样子的。谢谢你的帮助,这比我想做的更有意义。你会推荐什么资源让我更好地了解这门语言?@Crawlersout-继续努力,这只是时间的问题,继续练习。