我老实说不知道如何解决这个问题。我是一名新程序员,我需要帮助。 [英] I Honestly Have No Idea How To Fix This. I Am A New Programmer, And I Need Help.
问题描述
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);
}
}
}
我不断收到此错误:
错误5预期的类,委托,枚举,接口或结构
错误6预期的类,委托,枚举,接口或结构
错误7预期的类,委托,枚举,接口或结构
错误1类,结构或接口成员声明中的标记'{'无效
错误2方法必须具有返回类型
错误3方法必须具有返回类型
错误4方法必须具有返回类型
错误8类型或命名空间定义,或者结束 - 文件预期
代码块添加 - OriginalGriff [/ edit]
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]
推荐答案
正如Wes所说,大多数问题都是由于对分号的过度热情使用!
C#中的分号是一个语句终结符,所以将它放在一个开放的花括号之前永远不会给你什么期望! :笑:
此外,你有一些与你的CalcNet方法有关的奇数括号:
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:
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:
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:
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:
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!
这篇关于我老实说不知道如何解决这个问题。我是一名新程序员,我需要帮助。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!