473,324 Members | 2,313 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Tax rate code returning wrong output

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
9 1395
gpraghuram
1,275 Expert 1GB
I think the first if should be if(dectaxableIncome <= 38000)


Raghu
Aug 12 '08 #2
pejy69
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
r035198x
13,262 8TB
What is the code
Expand|Select|Wrap|Line Numbers
  1. dectax = dectaxableIncome * 19.5m / 100;
supposed to be doing?
Aug 12 '08 #4
pejy69
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
JosAH
11,448 Expert 8TB
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
r035198x
13,262 8TB
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
pejy69
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
9,208 Expert Mod 8TB
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
3,256 Expert 2GB
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

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

Similar topics

242
by: James Cameron | last post by:
Hi I'm developing a program and the client is worried about future reuse of the code. Say 5, 10, 15 years down the road. This will be a major factor in selecting the development language. Any...
25
by: Victor Bazarov | last post by:
In the project I'm maintaining I've seen two distinct techniques used for returning an object from a function. One is AType function(AType const& arg) { AType retval(arg); // or default...
5
by: Alfonso Morra | last post by:
Hi, What is the recomended way of returning an STL container (e.g. std::string, std::vector etc fom a function? Is it by simply returning a local variable? (I doubt it) std::string...
5
by: Michael Hiegemann | last post by:
Hello, I am unaware whether this is the right group to ask. Please point me to another forum if required. I would like to replace a Fortran function by one which is written in C. The function...
289
by: napi | last post by:
I think you would agree with me that a C compiler that directly produces Java Byte Code to be run on any JVM is something that is missing to software programmers so far. With such a tool one could...
9
by: Andy_Khosravi | last post by:
I'm an entry-level VBA programmer that is almost entirely self-taught. This means that while I have adequate knowledge of VBA in some areas, I have several gaps in others that may seem obvious to...
6
by: Programador | last post by:
I'm getting this error when running this program: Cannot calculate rate using the arguments provided Module Module1 Sub Main() Rate(360, -694.44444444444446, 244274.69178082192) End Sub
0
by: k1ngdrew | last post by:
I am trying to use mshtml to parse a web page without using IE. I create the HTMLDocument object, and then assign to it the output value from createDocumentFromUrl(). I know that this is at least...
4
by: Dimitrios Apostolou | last post by:
Hello list, I want to limit the download speed when using urllib2. In particular, having several parallel downloads, I want to make sure that their total speed doesn't exceed a maximum value. ...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.