Jump to content

How to code this algorithm

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
5 replies to this topic

#1
reja

reja

    Newbie

  • Members
  • PipPip
  • 12 posts
The algorithm is for determining the tax that a person has to pay based on his table income.How do i create a C#-based application,the GUI design and the programming code for the following pseudocode.Help me as i am new to C#.

Read taxable income
Set tax =0
If taxableIncome is less than or equal to 3800 Then
Calculate tax (tax=19.5% of 3800)
EndIf

If taxableIncome is more than 38000 and less than or equal to 60000 Then
Calculate tax(tax=19.5% of 3800 + 33% of 60000-38000)
EndIf

If taxableIncome is more than 60000 Then
Calculate tax(tax=19.5% of 3800 + 33% of 60000-38000 +39% of taxable income -60000)
EndIf

#2
Computer Engineer

Computer Engineer

    Newbie

  • Members
  • PipPip
  • 14 posts
please can you explain what do you mean by (taxableIncome)
is it the incomming salary or what?????

#3
reja

reja

    Newbie

  • Members
  • PipPip
  • 12 posts
taxableIncome is the name given for the variable...taxable income is the income received by a person and the person is being taxed according to his income

#4
cdg10620

cdg10620

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 389 posts
Set up a text box asking for the user to enter their taxable income and give them a submit button. Somewhere on the page you will want to add a label and show the user the end result of the calculation:

Your code in the codebehind (.cs file) should look something like this:

namespace myNamespace
{
	class myClass : System.Web.UI.Page
	{
		double taxibleIncome = 0.0;
		double tax = 0.0;
		
		protected override void OnInit( EventArgs e )
		{
			base.OnInit( e );
			this.btnSubmit.Click += new EventHandler( OnSubmitClick );
		}
		
		private void OnSubmitClick( object sender, EventArgs e )
		{
			this.lblTax.Text = this.CalculateTax( this.txtTaxableIncome.Text );
		}
		
		private double CalculateTax( double taxableIncome )
		{
			double result = 0.0;
			
			switch( taxableIncome )
			{
				case( taxableIncome <= 38000.00 )
					// do calculation
					break;
				case( taxableIncome > 38000.00 && taxableIncome <= 60000.00 )
					// do calculation
					break;
				case( taxableIncome > 60000.00 )
					// do calculation
					break;
				default:
					// throw error message
					break;
			}
			
			return result;
		}
	}
}

Code spacing may look bad cause I wrote this up quickly in Notepad++. The code is not perfect but you should get the idea.
-CDG10620
Software Developer

#5
reja

reja

    Newbie

  • Members
  • PipPip
  • 12 posts
oh thank you so much for helping.but i dont really understand the method that you have used because the one that my lecturer taught me was using the "If and Else" method....i will try modifying yours and add it to my code,thanks for helping me :)

#6
gokuajmes

gokuajmes

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 518 posts
did the code work,if yes please post your algorithm + code here so that members can benefit from the code Greetz