vendredi 16 mars 2018

Can't figure out why console.write keeps printing [on hold]

I'm programming a tax calculator that uses the information in the picture below. It is to be a terminal application. For the most part, my program is working fine, however, it is printing more than I want to (example attached).

I'm relatively new to using c# and programming so it is probably something simple. Here is my code:

using System;

class MainClass
{
    public static void Main(string[] args)
    {
        const int baserate = 6000;
        const int tierOne = 37000;
        const int tierTwo = 80000;
        const int tierThree = 180000;
        const float rateOne = 0.15F;
        const float rateTwo = 0.30F;
        const float rateThree = 0.37F;
        const float rateFour = 0.45F;

        Console.Write("Welcome to the personal income tax calculator\n");
        Console.Write("Please enter your annual income:\n");
        uint income = Convert.ToUInt32(Console.ReadLine());
        Console.Clear();

        // 0 - 6000
        if (income <= baserate)
            Console.Write("No tax payable");
        // 6001 - 37000
        if (income <= tierOne && income > baserate)
            Console.Write("Tax payable at 15c on the dollar for every dollar over $6000\n");
            uint taxableIncome = income - baserate;
            uint taxPayable = (uint)(taxableIncome * rateOne);
            Console.Write("Total Tax is: {0}", taxPayable);
        // 37001 - 80000
        if (income <= tierTwo && income > tierOne)
            Console.Write("Tax payable at 30c on the dollar for every dollar over $37,000 plus $4,650\n");
            taxableIncome = income - tierOne;
            taxPayable = (uint)(taxableIncome * rateTwo) + 4650;
            Console.Write("Total tax is: {0}", taxPayable);
        // 80001 - 180000
        if (income <= tierThree && income > tierTwo)
            Console.Write("Tax payable at 37c on the dollar for every dollar over $80,000 plus $17,550\n");
            taxableIncome = income - tierTwo;
            taxPayable = (uint)(taxableIncome * rateThree) + 17550;
            Console.Write("Total tax is: {0}", taxPayable);
        // 180001 - 
        if (income > tierThree)
            Console.Write("Tax payable at 45c on the dollar for every dollar over $180,000 plus $54,550\n");
            taxableIncome = income - tierThree;
            taxPayable = (uint)(taxableIncome * rateFour) + 54550;
            Console.Write("Total tax is: {0}", taxPayable);
    }
}

My task/objective: Image1

My output with the issue: Image2

In image 2 my issue it gives the correct information "Total Tax is: etc." but then continues to print tax is: ... tax is: ... .

Aucun commentaire:

Enregistrer un commentaire