Link to home
Start Free TrialLog in
Avatar of VBBRett
VBBRett

asked on

Adding a function to a class

I tried to add a tax function to a class and it seems like it is not working.  here is the function and class below.  Now in the code below, I get the following errors:

      Invalid token 'double' in class, struct, or interface member declaration

and

'MarketingEmail.ShoppingCart.CalculateTax(string)': not all code paths return a value

What could be causing these errors and how do I fix this so that there is no error.  I want to be able to do the code in class so that all I have to do is call the function in my program based on my class.  Thanks!
namespace MarketingEmail
{
    public class ShoppingCart
    {

        private int shoppingcartid;
        private int shoppingcartitemid;
        private int shoppingcartitemcount;
        

        
         function double CalculateTax(string CustomerState)
        {
            double salestax;

            switch(CustomerState)
            {
                   

                case "Alabama":
                    salestax = 4.0;
                    break;

                case "Alaska":
                    salestax = 0.0;
                    break;

                case "Arizona":
                    salestax = 6.6;
                    break;

                case "Arkansas":
                    salestax = 6.0;
                    break;

                case "California":
                    salestax = 8.25;
                    break;

                case "Colorado":
                    salestax = 2.9;
                    break;

                case "Connecticut":
                    goto case "Arkansas";

                case "Delaware":
                    goto case "Alaska";
                    
                case "District of Columbia":
                    goto case "Arkansas";

                case "Florida":
                    goto case "Arkansas";

                case "Georgia":
                    goto case "Alabama";                    

                case "Hawaii":
                    goto case "Alabama";

                case "Idaho":
                    goto case "Arkansas";

                case "Illinois":
                    salestax = 6.25;
                    break;

                case "Indiana":
                    salestax = 7.0;
                    break;

                case "Iowa":
                    goto case "Arkansas";

                case "Kansas":
                    salestax = 5.3;
                    break;

                case "Kentucky":
                    goto case "Arkansas";
                    
                case "Louisiana":
                    goto case "Alabama";

                case "Maine":
                    salestax = 5.0;
                    break;

                case "Maryland":
                    goto case "Arkansas";

                case "Massachusetts":
                    salestax = 6.25;
                    break;

                case "Michigan":
                    goto case "Arkansas";

                case "Minnesota":
                    salestax = 6.875;
                    break;

                case "Mississippi":
                    goto case "Indiana";

                case "Missouri":
                    salestax = 4.225;
                    break;

                case "Montana":
                    goto case "Alaska";

                case "Nebraska":
                    salestax = 7.7;
                    break;

                case "Nevada":
                    salestax = 6.85;
                    break;

                case "New Hampshire":
                    goto case "Alaska";

                case "New Jersey":
                    goto case "Indiana";

                case "New Mexico":
                    salestax = 5.125;
                    break;                    

                case "NJ":
                    salestax = 7.0;
                    break;
            }

            return salestax;
        }

    }
}

Open in new window

Avatar of epichero22
epichero22
Flag of United States of America image

What line is the first error on?
ASKER CERTIFIED SOLUTION
Avatar of Todd Gerbert
Todd Gerbert
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of VBBRett
VBBRett

ASKER

OK, it appears that the not all code paths return a value is line 21 and it is the following line of code:

double CalculateTax(string CustomerState)
I didn't get that error when I copy & paste your code, just the two matters I pointed out. Can you re post your code as it is now?