它不会给我从mod的销售总额和税收模式是关闭或东西 [英] It wont give me the sales total from the mod and the tax mod is off or something

查看:74
本文介绍了它不会给我从mod的销售总额和税收模式是关闭或东西的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

       class Program
    {


        static void Main(string[] args)
        {
            string customerName = "", state = "";
            int quantity = 0;
            double price = 0, sales = 0, tax = 0;

            Console.WriteLine("\n\nWelcome to the Sales Tax Calculator");

            Console.Write("\n\nPlease enter in the customer name:  ");
            customerName = Console.ReadLine();
            Console.Write("\n\nPlease enter in the State (NY / NJ / FL):  ");
            state = Console.ReadLine();
            Console.Write("\n\nPlease enter in the number of items purchased:  ");
            quantity = Convert.ToInt32(Console.ReadLine());
            Console.Write("\n\nPlease enter in the unit price of the item:  ");
            price = Convert.ToDouble(Console.ReadLine());



            sales = computeTotal(quantity, price);

            tax = computeTax(sales, state);

            Console.WriteLine(customerName + " your total sales are:  ");

            Console.WriteLine("Your total with taxes is:  " + tax);


            Console.ReadLine();
            
        }
        public static double computeTotal(int quantity, double price)
        {
            return (quantity * price);
        }

        public static double computeTax(double sales, string state)
        {
            double taxAmt = 0;

            if (state == "NY")
                taxAmt = sales * .04;
            else if (state == "NJ")
                taxAmt = sales * .07;
            else if (state == "FL")
                taxAmt = sales * .06;

            return taxAmt;


        }
    }
}

What I have tried:

Thank you AGAIN!!  Now when it is ran the calculations are simply not working right.  I don't know what I did.  The code in its entirety with corrections is above.  What am I doing wrong.  I tried messing with calculations but that only gave me lots of errors.  This is a tough one.

Thank you for helping with the module.  It looks wonderful. Everything looks good except the bold, underlined text above.  It keeps giving me an error of CS1503 for (state, sales)

I have tried everything I could possibly think of.  I am still learning and doing some of my brother's old work sheets from college to get a better handle on this programming stuff.

推荐答案

语法是错了,应该是:



The syntax is wrong, it should be:

if (state == "NY")
    taxAmt = sales * .04;
else if (state == "NJ")
    taxAmt = sales * .07;
else if (state == "FL")
    taxAmt = sales * .06;

return taxAmt;


Your problem is caused by calling the computeTax method using a string (state) as the first argument and a double (sales) as the second argument.

Your method computeTax Method expects a double as the first argument (sales) and a string (sate) as the second argument.

Either change the calling code to 

tax = computeTax(sales, state);

or change the computeTax method signature to 

public static double computeTax(String state, double sales)


这篇关于它不会给我从mod的销售总额和税收模式是关闭或东西的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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