错误 1 ​​无法将类型“double"隐式转换为“int".存在显式转换(您是否缺少演员表?) [英] Error 1 Cannot implicitly convert type 'double' to 'int'. An explicit conversion exists (are you missing a cast?)

查看:36
本文介绍了错误 1 ​​无法将类型“double"隐式转换为“int".存在显式转换(您是否缺少演员表?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对这个 C# 代码有一个错误,他们说错误 1 ​​无法将类型‘double’隐式转换为‘int’.存在显式转换(您是否缺少强制转换?)"错误在哪里?

I have an error with this C# code they said "Error 1 Cannot implicitly convert type 'double' to 'int'. An explicit conversion exists (are you missing a cast?)" where is the mistakes?

        Console.Write("Input money : ");
        float money;
        int tax;
        if (money < 10000)
        {
            tax = .05 * money;
        }
        else if (money <= 100000)
        {
            tax = .08 * money;
        }
        else
        {
            tax = .085 * money;
        }

        Console.WriteLine("Tax is {0}", tax);
        Console.ReadLine();
    }
}

推荐答案

将您的可变税收改为双倍

Change your variable tax to double

  double tax = 0;

工作代码,

Console.Write("Input money : ");
float money = Console.Read();          
double tax = 0;
if (money < 10000)
{
    tax = .05 * money;
}
else if (money <= 100000)
{
    tax = .08 * money;
}
else
{
    tax = .085 * money;
}

Console.WriteLine("Tax is {0}", tax);
Console.ReadLine();

这篇关于错误 1 ​​无法将类型“double"隐式转换为“int".存在显式转换(您是否缺少演员表?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆