943,584 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 454
  • C# RSS
Aug 12th, 2008
0

Help Please

Expand Post »
Hi My name is PJ.
I am a adult student.
I have read the rules regarding homework for those who are not willing to help themselves and i agree, but i have tried for the last few days to work this out and cant understand what i am doing wrong, if someone is kind enough to help and point me in the right direction, i would be very greatful. Below is the C# code i have. The program is meant to display the different tax brackets for the income within the amounts shown in the code below.
It's meant to display >$38000.00 shows 19.5%
>$60000.00 shows 33.0%
<$60001.00 shows 39.0%
No declaration shows 45.0% (sorry this hasnt been added yet). It displays the answer in a dollar form and does not show the right answer. Please explain what i have done and what i need to do to correct this. If you answer this, thankyou so much for taking the time to help. I am a first year student who is getting stuck with this.
Code posted with comments (// out) below:
C# Syntax (Toggle Plain Text)
  1. string strtaxableIncome;
  2. decimal dectaxableIncome;
  3. decimal dectax;
  4.  
  5. // Display "Plaese enter Income Tax"
  6. Console.WriteLine("Please enter Income Tax");
  7.  
  8. //Displap dollar sign
  9. Console.Write("$");
  10.  
  11. // Read taxableIncome
  12. strtaxableIncome = Console.ReadLine();
  13.  
  14. // Additional steps to convert string to decimal
  15. dectaxableIncome = decimal.Parse(strtaxableIncome);
  16.  
  17. // Set tax = 0
  18. dectax = 0m;
  19.  
  20. // If (taxableIncome <= 38000) Then
  21. if (dectaxableIncome <= 38000)
  22. {
  23. // Calculate tax (tax = 19.5% of 38000)
  24. dectax = dectaxableIncome * 19.5m / 100;
  25. }
  26. // End If
  27.  
  28. // If taxableIncome is more than 38000 and less than or equal to 60000 Then
  29. if (dectaxableIncome > 38000 && dectaxableIncome <= 60000)
  30. {
  31. // Calculate tax (tax = 19.5% of 38000 + 33% of 60000-38000)
  32. {
  33. dectax = dectaxableIncome * 19.5m / 100;
  34. dectax = dectax + dectaxableIncome * 33m / 100;
  35. }
  36. // End If
  37.  
  38. // If taxableIncome is more than 60000 Then
  39. if (dectaxableIncome > 60000)
  40. // Calculate tax (tax = 19.5% of 38000 + 33% of 60000-38000 + 39% of taxableIncome – 60000)
  41. {
  42. dectax = dectaxableIncome * 19.5m / 100;
  43. dectax = dectax + dectaxableIncome * 33m / 100;
  44. dectax = dectax + dectaxableIncome * 39m / 100;
  45. }
  46. // End If
  47.  
  48. // Display tax
  49. Console.Write("$");
  50. Console.Write(dectax);
  51.  
  52. // Keep window open
  53. Console.ReadKey();
Last edited by Tekmaven; Aug 12th, 2008 at 5:48 am. Reason: Code tags
Reputation Points: 10
Solved Threads: 0
Newbie Poster
pejy69 is offline Offline
2 posts
since Jul 2008
Aug 12th, 2008
0

Re: Help Please

Well first thing I see the lines

C# Syntax (Toggle Plain Text)
  1. // Display tax
  2. Console.Write("$");
  3. Console.Write(dectax);
  4.  
  5. // Keep window open
  6. Console.ReadLine();

Should be placed outside the last if block because you'll want them displayed every time. The next thing I see is that it looks like you're doing the math wrong. From my limited knowledge of income tax and how it's graduated it works on blocks of income.

Example:
A guy makes $60,000.
On the portion of his income above $38,000 he pays 33% income tax, or about $7,260
On the first $38,000 he pays 19.5%, or about $7,410
Meaning in total he pays $7,260 + $7,410, or $14,670

So the math looks likes
((60,000 - 38,000) * 0.33) + ((38,000) * 0.195))
Reputation Points: 11
Solved Threads: 4
Light Poster
nvmobius is offline Offline
39 posts
since Jul 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: How set backgroundimage to DataGridView + C#
Next Thread in C# Forum Timeline: Timer in windows service





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC