I am having trouble formatting a string in:
Console.WriteLine("SSN: {0} Gross: {1} Tax: {2}", t[x].SSN, t[x].Gross.ToString("C"), t[x].Tax.ToString("C"));
It should print:
SSN Gross Tax
123456789 $30,000.00 $8400.00
The full code is below:
using System;
namespace TaxPayerDemo
{
class Program
{
static void Main()
{
TaxPayer[] t = new TaxPayer[10];
int x;
for(x = 0; x < t.Length; ++x)
{
// Stores SSN
t[x] = new TaxPayer();
Console.Write("Please enter your SSN >> ");
t[x].SSN = Console.ReadLine();
// Stores Gross Income
Console.Write("Please enter your income >> ");
t[x].Gross = Convert.ToDouble(Console.ReadLine());
}
for (x = 0; x < t.Length; ++x)
{
t[x].calcTax();
Console.WriteLine();
Console.WriteLine("SSN: {0} Gross: {1} Tax: {2}", t[x].SSN, t[x].Gross.ToString("C"),
t[x].Tax.ToString("C"));
}
Console.ReadKey();
}
}
class TaxPayer
{
private const double LOW_TAXRATE = 0.15;
private const double HIGH_TAXRATE = 0.28;
public double Tax { get; set; }
public double Gross { get; set; }
public string SSN { get; set; }
public void calcTax()
{
if (Gross < 30000)
{
Tax = LOW_TAXRATE * Gross;
}
if (Gross >= 30000)
{
Tax = HIGH_TAXRATE * Gross;
}
}
}
}