423,850 Members | 1,661 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,850 IT Pros & Developers. It's quick & easy.

Tax rate code returning wrong output

P: 4
Hi
My name is PJ and i'm an adult student who requires a pointer in the right direction. Below is a snippett of the code that i believe i have something wrong in but cant work out what i have done wrong. The code is meant to:
Allow income to be entered and return a tax % rate.
<38000.00 meant to display 19.5%
>38000.00 but <60000.00 meant to display 33.0%
>60.000 meant to display 39.0%
It does not do this (it still displays dollar amounts) EG: enter 41000.00 as taxable income and the answer is 21525.00, and i have struggled with this for days, i need some guidance in the right direction, please
The code is as follows:

if (dectaxableIncome >= 38000)
dectax = dectaxableIncome * 19.5m / 100;
if (dectaxableIncome > 38000 && dectaxableIncome <= 60000)
dectax = dectaxableIncome * 19.5m / 100;
dectax = dectax + dectaxableIncome * 33m / 100;
if (dectaxableIncome > 60000)
dectax = dectaxableIncome * 19.5m / 100;
dectax = dectax + dectaxableIncome * 33m / 100;
dectax = dectax + dectaxableIncome * 39m / 100;
Aug 12 '08 #1
Share this Question
Share on Google+
9 Replies


gpraghuram
Expert 100+
P: 1,275
I think the first if should be if(dectaxableIncome <= 38000)


Raghu
Aug 12 '08 #2

P: 4
I think the first if should be if(dectaxableIncome <= 38000)


Raghu
I'd love to say yes, but no that does not work either, thanks for trying to help though
Aug 12 '08 #3

10K+
P: 13,264
What is the code
Expand|Select|Wrap|Line Numbers
  1. dectax = dectaxableIncome * 19.5m / 100;
supposed to be doing?
Aug 12 '08 #4

P: 4
What is the code
Expand|Select|Wrap|Line Numbers
  1. dectax = dectaxableIncome * 19.5m / 100;
supposed to be doing?
dividing every hundered dollars by 19.5%...... have a not quite understood this very well? I'm a first year student wanting to excel in this area, and we have had to develop this from pseudocode that was provided.
Aug 12 '08 #5

Expert 10K+
P: 11,448
Hi
My name is PJ and i'm an adult student who requires a pointer in the right direction. Below is a snippett of the code that i believe i have something wrong in but cant work out what i have done wrong. The code is meant to:
Allow income to be entered and return a tax % rate.
<38000.00 meant to display 19.5%
>38000.00 but <60000.00 meant to display 33.0%
>60.000 meant to display 39.0%
It does not do this (it still displays dollar amounts) EG: enter 41000.00 as taxable income and the answer is 21525.00, and i have struggled with this for days, i need some guidance in the right direction, please
Your code doesn't reflect the logic you just described; it should be something
like this:

Expand|Select|Wrap|Line Numbers
  1. if (income < 38000) percentage= 19.5;
  2. else if (income < 60000) percentage= 33.0; // income is >= 38000 here
  3. else percentage= 39.0; // income is >= 60000 here
  4.  
btw, this is the C and C++ forum, not the C# forum but in this particular case
it doesn't matter much.

kind regards,

Jos
Aug 12 '08 #6

10K+
P: 13,264
For your description I would have expected something like ...

Expand|Select|Wrap|Line Numbers
  1. double rate = 0.0;
  2. if(enteredAmount < 38000) {
  3.    rate = 19.5;
  4. }
  5. else if(enteredAmount < 60000) {
  6.     rate = 33;
  7. }
  8. else if ( .....
Aug 12 '08 #7

P: 4
For your description I would have expected something like ...

Expand|Select|Wrap|Line Numbers
  1. double rate = 0.0;
  2. if(enteredAmount < 38000) {
  3.    rate = 19.5;
  4. }
  5. else if(enteredAmount < 60000) {
  6.     rate = 33;
  7. }
  8. else if ( .....
Thankyou for that.... i will work on that and alter things a little
Aug 12 '08 #8

weaknessforcats
Expert Mod 5K+
P: 9,196
I am moving this to the .NET forum.

In C++ the <, >, >=, etc.. operators don't work as expected for floating point. Perhaps in C# it's different.
Aug 12 '08 #9

Curtis Rutland
Expert 2.5K+
P: 3,256
Do not double post your questions. If you are unsure where to post your question, the Mods can move it for you, but don't post it twice. It makes it hard for everyone to know what answers have been given and to keep track of information.

I have merged these threads.

MODERATOR
Aug 12 '08 #10

Post your reply

Sign in to post your reply or Sign up for a free account.