i am trying to figure it out, and i cant get the income and the SSN to show

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Assignment5_Koch
{
    class Rates
    {
        public readonly int incomeLimit;

        public readonly double lowTaxRate;

        public readonly double highTaxRate;

        public Rates()
        {
            incomeLimit = 30000;
            lowTaxRate = .15;
            highTaxRate = .28;


        }

        public Rates(int limit, double lowRate, double highRate)
        {
            incomeLimit = limit;
            lowTaxRate = lowRate;
            highTaxRate = highRate;

            Taxpayer tt = new Taxpayer();
            tt.taxOwed = tax;
        }
        public void CalculateTax(double income)
        {
            double tax;

            if (income < incomeLimit)
            {
                tax = income * lowTaxRate;
            }
            if (income > incomeLimit)
            {
                tax = income * highTaxRate;
            }
         
        }
    }



    class Taxpayer// : IComparable
    {
        public string socialSecurityNumber { get; set; }
        public int yearlyGrossIncome { get; set; }
        public readonly double taxOwed;

        public void getRates()
        {
            int incomeLimit;
            double lowRate;
            double highRate;


            Console.WriteLine("Do you want default values (enter D) or enter your own (enter O)?");
            char values = Convert.ToChar(Console.ReadLine());
            if (values == 'd' || values == 'D')
            {
                Rates deval = new Rates();
                incomeLimit = deval.incomeLimit;
                lowRate = deval.lowTaxRate;
                highRate = deval.highTaxRate;
                deval.CalculateTax(yearlyGrossIncome);

            }
            if (values == 'o' || values == 'O')
            {
                Console.WriteLine("Enter the dollar limit:");
                incomeLimit = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("Enter the low rate:");
                lowRate = Convert.ToDouble(Console.ReadLine());
                Console.WriteLine("Enter the high rate:");
                highRate = Convert.ToDouble(Console.ReadLine());

            }

        }
    }
    class assignment5_Koch
    {
        public static void Main(string[] args)
        {
            string[] socialSecurityNumber = new string[5]; //array for SSNs
            int[] grossIncome = new int[5];           //array for gross Incomes
            double[] taxArray = new double[5];
            string inputstring;

            for (int x = 0; x < socialSecurityNumber.Length; ++x)
            {
                Console.WriteLine("Enter Social Security Number for taxpayer 1:");
                inputstring = Console.ReadLine();
                socialSecurityNumber[0] = inputstring;
                Console.WriteLine("Enter gross income for taxpayer 1:");
                inputstring = Console.ReadLine();
                grossIncome[0] = Convert.ToInt32(inputstring);
                Taxpayer own = new Taxpayer();
                own.yearlyGrossIncome = grossIncome[0];
                Rates tp1 = new Rates();
                tp1.CalculateTax(own.yearlyGrossIncome);
                
                own.getRates();
                taxArray[0] = 0 ;
            }
            for (int x = 0; x < socialSecurityNumber.Length; ++x)
            {
                Console.WriteLine("Taxpayer #1 SSN: {0} income ${1} Tax is ${2}", socialSecurityNumber, grossIncome);
            }
        }
    }
}

Recommended Answers

All 7 Replies

Console.WriteLine("Taxpayer #1 SSN: {0} income ${1} Tax is ${2}", socialSecurityNumber[x], grossIncome[x]);

You still need to add the tax in there.

but still, i cant see the all array it only show me the data for the first taxpayer in the first line

This code

for (int x = 0; x < socialSecurityNumber.Length; ++x)
            {
                Console.WriteLine("Enter Social Security Number for taxpayer 1:");
                inputstring = Console.ReadLine();
                socialSecurityNumber[0] = inputstring;
                Console.WriteLine("Enter gross income for taxpayer 1:");
                inputstring = Console.ReadLine();
                grossIncome[0] = Convert.ToInt32(inputstring);
                Taxpayer own = new Taxpayer();
                own.yearlyGrossIncome = grossIncome[0];
                Rates tp1 = new Rates();
                tp1.CalculateTax(own.yearlyGrossIncome);
                
                own.getRates();
                taxArray[0] = 0 ;
            }

The [0] indexes should be [x]. You also need to store the actual tax value into the taxArray rather than zero.

i still cannot show the tax after calculation it show the same number as the income

No input validation or error checking

using System;

namespace TaxPayerDemo {
    class Taxpayer {
        String ssn;
        double yearlyGrossIncome;
        double taxOwed;

        public String SSN {
            get { return ssn; }
            set { ssn = value; }
        }

        public double YearlyGrossIncome {
            get { return yearlyGrossIncome; }
            set {
                yearlyGrossIncome = value;
                if (yearlyGrossIncome < 30000) {
                    taxOwed = .15 * yearlyGrossIncome;
                } else {
                    taxOwed = .28 * yearlyGrossIncome;
                }
            }
        }

        public double TaxOwed {
            get { return taxOwed; }
        }
    }

    class TaxPayerDemo {
        static void Main(string[] args) {
            Taxpayer[] people = new Taxpayer[10];
            for (int i = 0; i < people.Length; i++) {
                people[i] = new Taxpayer();
                Console.WriteLine("Please enter SSN for person #{0}", i + 1);
                people[i].SSN = Console.ReadLine();
                Console.WriteLine("Please enter Income for person #{0}", i + 1);
                people[i].YearlyGrossIncome = Double.Parse(Console.ReadLine());
            }

            Console.WriteLine();

            for (int i = 0; i < people.Length; i++) {
                Console.WriteLine("{0} - {1:c} - {2:c}", people[i].SSN, people[i].YearlyGrossIncome, people[i].TaxOwed);
            }

            Console.ReadLine();
        }
    }
}

much clear and clean i understood everything thanks, i appreciate it

if i need to ask you another question, i will need to open another thread ?

If the question is about something different, then please open another thread. It makes it easier to find when people use search to look for previous problems. Also name your new thread as close to the problem as you can, for example "Help" is bad, "NullReferenceException when accessing array element" is good.

commented: Great effort, like the image you attached. :) +9
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.