Click here to Skip to main content
15,895,192 members
Please Sign up or sign in to vote.
1.75/5 (4 votes)
See more:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Program_6
{
    class Program
    {
        static double rate, hours, tax, gross, depCost, net;
        static int numOfDep;

        static void Main();
        {
            GetData();
            CalcNet();
            DspData();
        }
        static void GetData();
        {
            Console.Write("Hours worked: ");
            hours=double.Parse(Console.ReadLine());
            Console.Write("Hourly rate: ");
            rate=double.Parse(Console.ReadLine());
            Console.Write("Dependents: ");
            numOfDep=Int32.Parse(Console.ReadLine());
         }
        static void CalcNet();
        {
            if (hours > 40) //factors in overtime pay
            {
            gross = Math.Round((hours - 40) * rate * 1.5 + rate * 40,2);
            }
            else
            {
            gross = Math.Round(hours*rate,2);
            }
        }
        {
            depCost = Math.Round(numOfDep*25.50,2);
            tax = Math.Round((gross-depCost)*.23,2);
            net = Math.Round(gross-depCost-tax);
        }
        static void DspData();
        {
            Console.WriteLine("Hours Worked:\t\t{0,10}", hours);
            Console.WriteLine("Hourly Rate:\t\t{0,10}", rate);
            Console.WriteLine("Dependants:\t\t{0,10}", numOfDep);
            Console.WriteLine("Gross Pay:\t\t{0,10}", gross);
            Console.WriteLine("Deductions:\t\t{0,10}", tax);
            Console.WriteLine("\t\t\t-----------");
            Console.WriteLine("Net pay:\t\t{0,10}", net);
        }
    }
}


and i keep getting this error:
Error 5 Expected class, delegate, enum, interface, or struct
Error 6 Expected class, delegate, enum, interface, or struct
Error 7 Expected class, delegate, enum, interface, or struct
Error 1 Invalid token '{' in class, struct, or interface member declaration
Error 2 Method must have a return type
Error 3 Method must have a return type
Error 4 Method must have a return type
Error 8 Type or namespace definition, or end-of-file expected

[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 21-Oct-14 8:03am
v2
Comments
[no name] 21-Oct-14 14:00pm    
Well for a start, get rid of the semicolons at the end of your method declarations.
You should debug and see what are the issue.

1 solution

As Wes says, most of the problems are due to a little over-enthusiastic use of semicolons!
The semicolon in C# is a statement terminator, so placing it before an open curly bracket is never going to give you what you expect! :laugh:

In addition, you have some odd brackets relating to your CalcNet method:
C#
static void CalcNet();
{
    if (hours > 40) //factors in overtime pay
    {
    gross = Math.Round((hours - 40) * rate * 1.5 + rate * 40,2);
    }
    else
    {
    gross = Math.Round(hours*rate,2);
    }
}
{
    depCost = Math.Round(numOfDep*25.50,2);
    tax = Math.Round((gross-depCost)*.23,2);
    net = Math.Round(gross-depCost-tax);
}

It's possible that you meant the second section to be a separate method altogether:
C#
static void CalcNet();
{
    if (hours > 40) //factors in overtime pay
    {
    gross = Math.Round((hours - 40) * rate * 1.5 + rate * 40,2);
    }
    else
    {
    gross = Math.Round(hours*rate,2);
    }
}
static void AnotherMethodAlltogether()
{
    depCost = Math.Round(numOfDep*25.50,2);
    tax = Math.Round((gross-depCost)*.23,2);
    net = Math.Round(gross-depCost-tax);
}

Or you just made a mistake and it should be:
C#
public static void CalcNet()
{
    if (hours > 40) //factors in overtime pay
    {
        gross = Math.Round((hours - 40) * rate * 1.5 + rate * 40,2);
    }
    else
    {
        gross = Math.Round(hours*rate,2);
    }
    depCost = Math.Round(numOfDep*25.50,2);
    tax = Math.Round((gross-depCost)*.23,2);
    net = Math.Round(gross-depCost-tax);
}

I'll assume that latter! :laugh:
Try this:
C#
namespace Program_6
{
    public class Program
    {
        private static double rate, hours, tax, gross, depCost, net;
        private static int numOfDep;

        static void Main()
        {
            GetData();
            CalcNet();
            DspData();
        }
        public static void GetData()
        {
            Console.Write("Hours worked: ");
            hours=double.Parse(Console.ReadLine());
            Console.Write("Hourly rate: ");
            rate=double.Parse(Console.ReadLine());
            Console.Write("Dependents: ");
            numOfDep=Int32.Parse(Console.ReadLine());
         }
        public static void CalcNet()
        {
            if (hours > 40) //factors in overtime pay
            {
                gross = Math.Round((hours - 40) * rate * 1.5 + rate * 40,2);
            }
            else
            {
                gross = Math.Round(hours*rate,2);
            }
            depCost = Math.Round(numOfDep*25.50,2);
            tax = Math.Round((gross-depCost)*.23,2);
            net = Math.Round(gross-depCost-tax);
        }
        public static void DspData()
        {
            Console.WriteLine("Hours Worked:\t\t{0,10}", hours);
            Console.WriteLine("Hourly Rate:\t\t{0,10}", rate);
            Console.WriteLine("Dependants:\t\t{0,10}", numOfDep);
            Console.WriteLine("Gross Pay:\t\t{0,10}", gross);
            Console.WriteLine("Deductions:\t\t{0,10}", tax);
            Console.WriteLine("\t\t\t-----------");
            Console.WriteLine("Net pay:\t\t{0,10}", net);
        }
    }
}
I can't say it will work, but it should at least compile!
 
Share this answer
 
Comments
[no name] 21-Oct-14 15:54pm    
Are you sure you don't mean "as Richard says..."? :-)
OriginalGriff 21-Oct-14 16:02pm    
Smartarse! :laugh:
[no name] 21-Oct-14 16:04pm    
It's a rough job but someone has to do it...

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