我得到這個錯誤在我的代碼中,我試圖讓用戶輸入僱員的名字,他們賺了多少比收入通過所有的稅收數學,然後給用戶一個輸出輸入的姓名和拿回家的稅款。我必須使用兩個類。我哪裏錯了?請幫忙。Stackoverflowexception未處理。試圖獲取takehomepay價值
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace consoleapplication9
{
public class takehomepay
{
static void Main(String[] args)
{
const decimal commission = 0.7M; // Commision rate
const decimal federaltax = 0.18M; // federal tax rate
const decimal retirement = 0.10M; // retirement rate
const decimal socialsecurity = 0.06M; // social security rate
string employeeName;
decimal commcost = 0; // commision cost
decimal fedtaxcost = 0; // federal tax cost
decimal retirecost = 0; // retirement cost
decimal socseccost = 0; // social security cost
decimal totalwithholdingcost = 0; // total withholding
decimal takehomepay = 0; // amount taken home
decimal totalSales = 0;
Console.Write("\nEnter employees name: ");
employeeName = Console.ReadLine();
Console.Write("Enter the total sales amount for the week:");
totalSales = Convert.ToDecimal(Console.ReadLine());
var employee = new Employee(employeeName, totalSales);
Console.Write(employee);
Console.Read();
//Calculations
commcost = commission * totalSales;
fedtaxcost = federaltax * commcost;
retirecost = retirement * commcost;
socseccost = socialsecurity * commcost;
totalwithholdingcost = federaltax + retirement + socialsecurity;
takehomepay = commcost - totalwithholdingcost;
}
}
public class Employee
{
private string employeeName;
private decimal totalSales;
public Employee()
{
}
public Employee(string Name)
{
employeeName = Name;
}
public Employee(string Name, decimal Sales)
{
employeeName = Name;
totalSales = Sales;
}
public string EmployeeName
{
get
{
return employeeName;
}
set
{
employeeName = value;
}
}
public decimal takehomepay
{
get
{
return takehomepay;
}
set
{
takehomepay = value;
}
}
public override string ToString()
{
return "Employee: " + employeeName +
"\nTake home pay: " + takehomepay;
}
}
}
我改變了你的建議,但現在我得到的錯誤「一個得到或設置acceutor期望」 public decimal takehomepay {get;設置;) { 得到 { return takehomepay; } set { takehomepay = value; } } } – 2014-09-26 05:24:16
@ nicko'connor刪除最後一位,從字面上只是有'decimal takehomepay {get;設置;)'並且移除'{get {return takehomepay; } set {takehomepay = value; }}}' – 2014-09-26 05:26:37
請注意,它應該''而不是'''在'set'之後'' – 2014-09-26 05:29:39