Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/299.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.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# - Fatal编程技术网

C# 我得到了这个错误。无法隐式转换类型';双倍';至';十进制';。存在明确的对话(是否缺少演员阵容?)

C# 我得到了这个错误。无法隐式转换类型';双倍';至';十进制';。存在明确的对话(是否缺少演员阵容?),c#,C#,我得到了这个错误。无法将类型“double”隐式转换为“decimal”。存在明确的对话(你错过演员阵容了吗?)我对C#有点生疏。我已经两年没做什么了 我要写这个 编写一个控制台应用程序,根据提交状态和 应纳税所得额。 该程序应提示用户输入单身或已婚(或退出)的申请状态。如果 如果输入了任何其他内容,则应显示错误消息并重复输入。 如果状态为单身或已婚,则输入应税收入并打印税额。 此过程应重复,直到输入Quit using System; using System.Collections.Gene

我得到了这个错误。无法将类型“double”隐式转换为“decimal”。存在明确的对话(你错过演员阵容了吗?)我对C#有点生疏。我已经两年没做什么了

我要写这个 编写一个控制台应用程序,根据提交状态和 应纳税所得额。 该程序应提示用户输入单身或已婚(或退出)的申请状态。如果 如果输入了任何其他内容,则应显示错误消息并重复输入。 如果状态为单身或已婚,则输入应税收入并打印税额。 此过程应重复,直到输入Quit

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void gobutton_Click(object sender, EventArgs e)
        {
            decimal income  //hold income value
            decimal tax     //hold tax value  

            //get income value
            income = int.Parse(textBox2.Text);


            //Display the output ino the tax output label
            taxoutputlabel.Text = tax;

            if (textBox1.Text == "single")
                if (income <= 8700)
                    tax = income * 0.10;
                else if (income <= 35350)
                    tax = 4867.50 + (35350 - 8700) * 0.15;
                else if (income <= 85650)
                    tax = 17442.50 + (85650 - 35350) * 0.25;
                else if (income <= 178650)
                    tax = 43482.50 + (178650 - 85650) * 0.28;
                else if (income <= 388350)
                    tax = 112683.50 + (388350 - 178650) * 0.35;
            else if (textBox1.Text == "marriage, married")
                if (income <= 17400)
                        tax = income * 0.10;
                else if (income <= 70700)
                        tax = 4867.50 + (70700 - 17400) * 0.15;
                else if (income <= 142700)
                        tax = 17442.50 + (142700 - 70700) * 0.25;
                else if (income <= 217450)
                        tax = 43482.50 + (217450 -142700) * 0.28;
                else if (income <= 388350)
                        tax = 112683.50 + (388350 - 178650) * 0.35;
            else if (textBox1.Text == "divorced")
                if (income <= 8700)
                    tax = income * 0.10;
                else if (income <= 35350)
                    tax = 4867.50 + (35350 - 8700) * 0.15;
                else if (income <= 85650)
                    tax = 17442.50 + (85650 - 35350) * 0.25;
                else if (income <= 178650)
                    tax = 43482.50 + (178650 - 85650) * 0.28;
                else if (income <= 388350)
                    tax = 112683.50 + (388350 - 178650) * 0.35;

        }

        private void exitbutton_Click(object sender, EventArgs e)
        {
            //closes form
            this.Close();
        }
    }
}
使用系统;
使用System.Collections.Generic;
使用系统组件模型;
使用系统数据;
使用系统图;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用System.Windows.Forms;
命名空间Windows窗体应用程序2
{
公共部分类Form1:Form
{
公共表格1()
{
初始化组件();
}
私有void Form1\u加载(对象发送方、事件参数e)
{
}
私有void gobutton_Click(对象发送方,事件参数e)
{
十进制收入//持有收入价值
十进制税//保留税值
//获得收入价值
income=int.Parse(textBox2.Text);
//显示税务输出标签中的输出
taxoutputlabel.Text=税;
如果(textBox1.Text==“单个”)
if(income编译器默认将0.10(和任何其他分数)视为
双精度

要告诉编译器它是十进制数,必须使用
m
后缀,如下所示:

tax = income * 0.10m;
必须对方程式中使用的所有数字执行此操作。例如:

tax = 4867.50m + (35350m - 8700m) * 0.15m; 

简单地转换为十进制将无法解析

tax = Convert.ToDecimal(4867.50 + (70700 - 17400) * 0.15);

您介意指出错误发生的确切位置吗?任何“tax=”的位置is和taxoutputlabel.Text=tax;有相同的错误try
tax=income*0.10m
;而且代码甚至没有编译。
decimal income//hold income value
,在结尾等处没有分号。请在提问时对这些错误更加谨慎。谢谢,正如我说过的那样,我已经停止编码大约两年了。S很抱歉没有看到。我知道这很简单。非常感谢。taxoutputlabel.Text=tax;存在无法将类型Decimal隐式转换为字符串的错误。请使用
tax.ToString()
.taxoutputlabel.Text=tax.ToString();现在表示使用未赋值局部变量“tax”@MatthewHunt,这意味着您需要
将其初始化为一个值,例如
var-tax=0.0;
@MethodMan,如果OP想要使用
var
,那么他应该将其初始化为
0.0m
,以便编译器知道它是十进制数。