473,748 Members | 9,416 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Tax rate code returning wrong output

4 New Member
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 (dectaxableInco me >= 38000)
dectax = dectaxableIncom e * 19.5m / 100;
if (dectaxableInco me > 38000 && dectaxableIncom e <= 60000)
dectax = dectaxableIncom e * 19.5m / 100;
dectax = dectax + dectaxableIncom e * 33m / 100;
if (dectaxableInco me > 60000)
dectax = dectaxableIncom e * 19.5m / 100;
dectax = dectax + dectaxableIncom e * 33m / 100;
dectax = dectax + dectaxableIncom e * 39m / 100;
Aug 12 '08 #1
9 1405
gpraghuram
1,275 Recognized Expert Top Contributor
I think the first if should be if(dectaxableIn come <= 38000)


Raghu
Aug 12 '08 #2
pejy69
4 New Member
I think the first if should be if(dectaxableIn come <= 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 MVP
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 New Member
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 Recognized Expert MVP
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 MVP
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 New Member
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 Recognized Expert Moderator Expert
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 Recognized Expert Specialist
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
13405
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 comments on past experience, research articles, comments on the matter would be much appreciated. I suspect something like C would be the best based on comments I received from the VB news group. Thanks for the help in advance James Cameron
25
2938
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 construction and then.. // some other processing and/or changing 'retval' return retval; }
5
2276
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 foo(const std::string& rhs) { std::string var = rhs ; var += " received" ;
5
2719
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 shall provide the same interface for the fortran code calling the library. Fortunately, this works - currently under WinNT - well for all functions which do not return a string, e.g.
289
1805
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 stay with C and still be able to produce Java byte code for platform independent apps. Also, old programs (with some tweaking) could be re-compiled and ported to the JVM. We have been developing such a tool over the last 2 years and currently...
9
2331
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 more experienced programmers. Please bear with me =) I'm having a problem that occurs intermittently (about 1 error per 1,000 transactions) with a routine I wrote. It would seem that the recordset command to .addnew is for whatever reason...
6
7475
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
3361
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 partially working, because I am able to access the HTMLDocument.title. However, when I try to read the output of the getElementsByTagName() member, I am getting length = 0 inside the IHTMLElementCollection object receiving the output. When I...
4
7218
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. I can't find a simple way to achieve this. After researching a can try some things but I'm stuck on the details: 1) Can I overload some method in _socket.py to achieve this, and perhaps
0
8984
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8823
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9530
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9363
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9238
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6793
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.