Jake
Jake

Reputation: 11

private void Method help C#

Currently having troubles using a method to calculate an outcome (taxes), in my calculator program. I looked in Murach's C# 2012 but i cant seem to find a solution for this error.

Error:

CS7036 "There is no argument given that corresponds to the required formal parameter"

here is my private void

 private void calcTaxes(decimal decGross, out decimal decFica, out decimal decState, out decimal decFederal)
    {
        decFica = (decGross * cdecFICA_RATE);
        decFederal = (decGross * cdecFEDERAL_RATE);
        decState = (decGross * cdecSTATE_RATE);
    }

I am trying to get the values of the Tax rates and plug them into my code.

 try
        {
            intHours = int.Parse(txtHours.Text);
            try
            {
                decRate = decimal.Parse(txtRate.Text);

                if (intHours >= 1 && intHours <= 50)
                    if (decRate >= 10.00M && decRate <= 15.00M)
                    {


                        decGross = calcGross(intHours, decRate);
                        decFica = calcTaxes(decGross);     //this
                        decFederal = calcTaxes(decGross);  //this  
                        decState = calcTaxes(decGross);    //And this are the issued areas.
                        decUnionDues = setUnionDues();

                        calcNetpay(decGross, decFica, decFederal, decState, decUnionDues, out decNetpay);

                        cdecTotalnetpay += decNetpay;
                        cintEmployeecount += 1;
                        decAveragenetpay = calcAveragenetpay();

                        lblGross.Text = decGross.ToString("C");
                        lblFica.Text = decFica.ToString("C");
                        lblState.Text = decState.ToString("C");
                        lblFederal.Text = decFederal.ToString("C");
                        lblUnionDues.Text = decUnionDues.ToString("C");
                        lblNetpay.Text = decNetpay.ToString("C");

                        lblTotalnetpay.Text = cdecTotalnetpay.ToString("C");
                        lblEmployeecount.Text = cintEmployeecount.ToString("N0");
                        lblAveragenetpay.Text = decAveragenetpay.ToString("C");

                        txtHours.Focus();

Anyone see what i cant?

Upvotes: 1

Views: 1481

Answers (3)

Koo SengSeng
Koo SengSeng

Reputation: 953

If you need to return the value in your code behind, then you can't declare your function as void. As void return nothing but processing the code in it, and that's it.

I would suggest you do a little more logic in the method, and return the function as decimal. This is a longer but clearer way to achieve your result:

private decimal calcTaxes(decimal decGross, int calcType)
{
    decimal decResult = 0;
    if (calcType == 1)
    {
        decResult = (decGross * cdecFICA_RATE);
    }
    else if (calcType == 2)
    {
        decResult = (decGross * cdecFEDERAL_RATE);
    }
    else if (calcType == 3)
    {
        decResult = (decGross * cdecSTATE_RATE);
    }

    return decResult;
}

And then modify the code where you called the function as below:

 decFica = calcTaxes(decGross, 1);
 decFederal = calcTaxes(decGross, 2);
 decState = calcTaxes(decGross, 3);    

Upvotes: 0

Sateesh Pagolu
Sateesh Pagolu

Reputation: 9606

You are missing out parameters in method call.

Try this

calcTaxes(decGross,out decFica,out decState,out decFederal)

After this call, decFica,decState,decFederal variables will have calculated.

As you can see, your private method has return type as void. So, it doesnt return anything.

You need to pass 3 parameters of type decimal to your private method which get updated with below code in your method.

    decFica = (decGross * cdecFICA_RATE);
    decFederal = (decGross * cdecFEDERAL_RATE);
    decState = (decGross * cdecSTATE_RATE);

Reference here

Upvotes: 1

Nikita Shrivastava
Nikita Shrivastava

Reputation: 3018

You need to call the function only once not thrice, like this :

calcTaxes(decGross,out decFica,out decState,out decFederal)

Upvotes: 1

Related Questions