C#: Error Please Help!

<PLEASE USE THIS TEMPLATE TO HELP YOU CREATE A GREAT POST!>

Hii, Im currently learning C# but I have a little bit of experience with Visual Basic language. I need to calculate the total week sales, contributions, federal tax, social security and retirement contributions.

I also need to build input, display, and calculation methods for each of the deductions. My final output should display all calculated values, including the total deductions and all defined constants.

<Below this line, add a link to the EXACT exercise that you are stuck at.>

<Below this line, in what way does your code behave incorrectly? Include ALL error messages.>
Severity Code Description Project File Line Suppression State
Error CS1519 Invalid token ‘{’ in class, struct, or interface member declaration Weekly Calculator Project C:\Users\gygad\Desktop\Weekly Calculator Solution\Weekly Calculator Project\Program.cs 52 Active

Error CS1519 Invalid token ‘+’ in class, struct, or interface member declaration Weekly Calculator Project C:\Users\gygad\Desktop\Weekly Calculator Solution\Weekly Calculator Project\Program.cs 53 Active

Error CS1519 Invalid token ‘+’ in class, struct, or interface member declaration Weekly Calculator Project C:\Users\gygad\Desktop\Weekly Calculator Solution\Weekly Calculator Project\Program.cs 53 Active

Error CS1519 Invalid token ‘;’ in class, struct, or interface member declaration Weekly Calculator Project C:\Users\gygad\Desktop\Weekly Calculator Solution\Weekly Calculator Project\Program.cs 53 Active

Error CS1519 Invalid token ‘;’ in class, struct, or interface member declaration Weekly Calculator Project C:\Users\gygad\Desktop\Weekly Calculator Solution\Weekly Calculator Project\Program.cs 53 Active

\Desktop\Weekly Calculator Solution\Weekly Calculator Project\Program.cs 57 Active

Error CS0501 ‘Program.CalculateFederalTax(double, double)’ must declare a body because it is not marked abstract, extern, or partial Weekly Calculator Project C:\Users\gygad\Desktop\Weekly Calculator Solution\Weekly Calculator Project\Program.cs 51 Active

Error CS0100 The parameter name ‘totalBeforeDeductions’ is a duplicate Weekly Calculator Project C:\Users\gygad\Desktop\Weekly Calculator Solution\Weekly Calculator Project\Program.cs 51 Active

Error CS0501 ‘.CalculateRetirement(double, double)’ must declare a body because it is not marked abstract, extern, or partial Weekly Calculator Project C:\Users\gygad\Desktop\Weekly Calculator Solution\Weekly Calculator Project\Program.cs 56 Active

Error CS0246 The type or namespace name ‘totalBeforeDeductions’ could not be found (are you missing a using directive or an assembly reference?) Weekly Calculator Project C:\Users\gygad\Desktop\Weekly Calculator Solution\Weekly Calculator Project\Program.cs 58 Active

Error CS0214 Pointers and fixed size buffers may only be used in an unsafe context Weekly Calculator Project C:\Users\gygad\Desktop\Weekly Calculator Solution\Weekly Calculator Project\Program.cs 58 Active

Error CS0208 Cannot take the address of, get the size of, or declare a pointer to a managed type (‘totalBeforeDeductions’) Weekly Calculator Project C:\Users\gygad\Desktop\Weekly Calculator Solution\Weekly Calculator Project\Program.cs 58 Active

Error CS0116 A namespace cannot directly contain members such as fields or methods Weekly Calculator Project C:\Users\gygad\Desktop\Weekly Calculator Solution\Weekly Calculator Project\Program.cs 58 Active

Error CS0116 A namespace cannot directly contain members such as fields or methods Weekly Calculator Project C:\Users\gygad\Desktop\Weekly Calculator Solution\Weekly Calculator Project\Program.cs 63 Active

Error CS0501 ‘.DisplayTotals(double, double, double, double, double, double, double)’ must declare a body because it is not marked abstract, extern, or partial Weekly Calculator Project C:\Users\gygad\Desktop\Weekly Calculator Solution\Weekly Calculator Project\Program.cs 63 Active

Error CS0103 The name ‘CalculateRetirement’ does not exist in the current context Weekly Calculator Project C:\Users\gygad\Desktop\Weekly Calculator Solution\Weekly Calculator Project\Program.cs 27 Active

Error CS0103 The name ‘CalculateRetirement’ does not exist in the current context Weekly Calculator Project C:\Users\gygad\Desktop\Weekly Calculator Solution\Weekly Calculator Project\Program.cs 28 Active

Error CS0103 The name ‘DisplayTotals’ does not exist in the current context Weekly Calculator Project C:\Users\gygad\Desktop\Weekly Calculator Solution\Weekly Calculator Project\Program.cs 29 Active

Error CS0103 The name ‘totalSalesCommission’ does not exist in the current context. Weekly Calculator Project C:\Users\gygad\Desktop\Weekly Calculator Solution\Weekly Calculator Project\Program.cs 53 Active

Error CS0103 The name ‘totalBeforeDeductions’ does not exist in the current context. Weekly Calculator Project C:\Users\gygad\Desktop\Weekly Calculator Solution\Weekly Calculator Project\Program.cs 53 Active

```

Replace this line with your code.
using System;

namespace Weekly_Calculator_Project
{
class Program
{
static void Main()
{
const double FEDERAL_TAX_RATE = .18;
const double RETIREMENT_CONTRIBUTION = .15;
const double SOCIAL_SECURITY_TAX = .09;

        double totalBeforeDeductions,
               totalSalesCommission,
               federalTaxRate,
               retirementContribution,
               socialSecurityTax;


        totalBeforeDeductions = GetTotal();
        totalSalesCommission = CalculateSales(totalBeforeDeductions, FEDERAL_TAX_RATE);
        federalTaxRate = CalculateFederalTax(totalSalesCommission, totalBeforeDeductions);
        retirementContribution = CalculateRetirement(federalTaxRate, RETIREMENT_CONTRIBUTION);
        socialSecurityTax = CalculateRetirement(federalTaxRate, SOCIAL_SECURITY_TAX);
        DisplayTotals(totalBeforeDeductions, totalSalesCommission, retirementContribution, socialSecurityTax,
            FEDERAL_TAX_RATE, RETIREMENT_CONTRIBUTION, SOCIAL_SECURITY_TAX);

        Console.ReadKey();
    }

    static double GetTotal()
    {
        string inValue;
        double total;
        Console.Write("Please enter the total sales: ");
        inValue = Console.ReadLine();
        total = double.Parse(inValue);
        return total;

    }

    static double CalculateSales(double totalBeforeDeductions, double FEDERAL_TAX_RATE)
    {
        return totalBeforeDeductions * FEDERAL_TAX_RATE;
    }

    static double CalculateFederalTax(double totalBeforeDeductions, double totalBeforeDeductions);
    {
        return totalSalesCommission + totalBeforeDeductions;
    }

    static double CalculateRetirement(double totalBeforeDeductions, double Deductions);
    {
        return totalBeforeDeductions* Deductions;
    }

    

    static void DisplayTotals(double totalBeforeDeductions, double totalSalesCommission, 
        double retirementContribution, double socialSecurityTax, double FEDERAL_TAX_RATE, 
        double RETIREMENT_CONTRIBUTION, double SOCIAL_SECURITY_TAX);
<do not remove the three backticks above>

What a huge pile of error messages, on my end (mono on linux) I just get:

$ mcs Program.cs
Program.cs(48,80): error CS0100: The parameter name `totalBeforeDeductions' is a duplicate
Program.cs(49,9): error CS9010: Primary constructor body is not allowed
Program.cs(54,9): error CS9010: Primary constructor body is not allowed
Program.cs(54,9): error CS8041: Primary constructor already has a body
Program.cs(62,246): error CS1525: Unexpected symbol `end-of-file'
Compilation failed: 5 error(s), 0 warnings

Which might be easier to deal with… if not, what information are you missing?

Those error messages should be very easy to google. You can also start with a minimal piece of code (namespace, class, and main method) and then add the other methods one at a time and compile between each small change.
Really, the error messages should be enough to point you at the problems, but if you’re having trouble interpreting them then this way you know that it’s the last thing you added that caused the error message and when you see the problem you can read the error message again and get a better understanding of what it meant

1 Like

Thank you very much!
Your code errors helps me because it points the real problems.
I appreciate your help, and if I can solve the problem I’ll publish the final code.

Have a nice day!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.