Hi,
Continuation of a previous thread. This is different question, so new thread. I have an array of 5 taxpayers. User enters 5 SSNs and Incomes. An array is instantiated to fill this data. I need to display all five objects listing SSN, income and tax. I am having difficulty because five of the same taxpayer prints over and over. I can't figure out how to display data for each. Used to using parallel arrays for this. Here is part of what I have. I have colored my weak attempt to get SSN, but I know it is wrong.
Thank you.
// Create a class named Taxpayer that has the following data members:
public class Taxpayer
{
//Social Security number (use type string, no dashes between groups). Use get and set accessors.
string SSN
{ get; set; }
int yearlyGrossIncome // Use get and set accessors.
{ get; set; }
public int taxOwed // Use read-only accessor.
{
get { return taxOwed; }
private set { }
}
// Implement a for-loop that will prompt the user to enter the Social Security Number and gross income.
for (x = 0; x < taxArray.Length; x++)
{
taxArray[x] = new Taxpayer();
Console.Write("Please enter the Social Security Number for taxpayer {0}: ", x);
SSN = Convert.ToString(Console.ReadLine());
//SSN = String.Format("{0:000-00-0000}");
Console.Write("Please enter the gross income for taxpayer {0}: ", x);
income = Convert.ToInt32(Console.ReadLine());
Taxpayer.GetRates();
}
// Implement a for-loop that will display each object as formatted taxpayer SSN, income and calculated tax.
for (int i = 0; i < 5; i++)
{
Console.WriteLine("Taxpayer # {0} SSN: {1}, Income is {2:c}, Tax is {3:c}", i, Taxpayer[i].SSN, income, tax);
}