Click here to Skip to main content
15,900,816 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
       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.
Posted
Updated 16-Jun-18 8:51am
v4

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;
 
Share this answer
 
v4
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)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900