Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,233 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,735 people online right now. Registration is fast and FREE... Join Now!




Follow up on Tax application- Function structures

2 Pages V  1 2 >  
Closed TopicStart new topic

Follow up on Tax application- Function structures, Still need some help. Can't get it to work completely correct yet

Phantom_of_the_opera
9 Mar, 2007 - 09:35 PM
Post #1

New D.I.C Head
*

Joined: 13 Nov, 2006
Posts: 43


My Contributions
.

This post has been edited by Phantom_of_the_opera: 3 May, 2007 - 10:41 AM
User is offlineProfile CardPM
+Quote Post

jstephens
RE: Follow Up On Tax Application- Function Structures
9 Mar, 2007 - 11:03 PM
Post #2

D.I.C Head
**

Joined: 7 Nov, 2005
Posts: 191



Thanked: 1 times
My Contributions
What is the exact error your are given? If you specify void in your functions then there is not need to use a return statement. Void means you are not returning any value. Also from taking a quick look at your code it looks like your are not returning any value just declaring if they are married and have kids.
User is offlineProfile CardPM
+Quote Post

horace
RE: Follow Up On Tax Application- Function Structures
10 Mar, 2007 - 01:24 AM
Post #3

D.I.C Addict
Group Icon

Joined: 25 Oct, 2006
Posts: 573



Thanked: 4 times
Dream Kudos: 50
My Contributions
for a start to you don't pass the information between the functions correctly, i.e. you assign gROSS2= Gross and PAID = paidPentrybefore you call getData()
try
CODE

getData(mar, chld, pen, NUMCH, Gross, paidPen);
float gROSS2= Gross;
float PAID = paidPen;
taxAmount(mar, chld, pen, children, gROSS2, PAID, TOTALFINAL);

User is offlineProfile CardPM
+Quote Post

Phantom_of_the_opera
RE: Follow Up On Tax Application- Function Structures
10 Mar, 2007 - 12:34 PM
Post #4

New D.I.C Head
*

Joined: 13 Nov, 2006
Posts: 43


My Contributions
.

This post has been edited by Phantom_of_the_opera: 3 May, 2007 - 10:41 AM
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Follow Up On Tax Application- Function Structures
10 Mar, 2007 - 12:54 PM
Post #5

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,230



Thanked: 40 times
Dream Kudos: 25
My Contributions
Perhaps I'm missing something...
CODE

int Newwage = 0, Exempt = 0, Percent = 0;
int TAXABLE = Percent;
float Total = 0, TaxPercent = 0;

In the code above, you assign Percent a value of 0, then assign TAXABLE the value of percent, which is 0. You don;t appear to change the value of TAXABLE.so it is always 0 in the function. It does not appear to get caught in any of your if statements, so it is never used to calculate Final. This means that Final will hold the same value you passed to the function in the first place, which is 0.

I may have missed something - can you explain each step your function is meant to take?

It may also be worth noting that the following comparison may not work the way you want it to:
CODE

if(TAXABLE > 0 || TAXABLE <=15000)

This says if TAXABLE is grater than 0 OR Less than or equal to 15000...any value greater than 0 will be caught by this, whereas I suspect you may have wanted an AND condition - meaning that value has to be between the two.

The same is true of your other multiple comparison.
User is online!Profile CardPM
+Quote Post

Phantom_of_the_opera
RE: Follow Up On Tax Application- Function Structures
10 Mar, 2007 - 01:28 PM
Post #6

New D.I.C Head
*

Joined: 13 Nov, 2006
Posts: 43


My Contributions
.

This post has been edited by Phantom_of_the_opera: 3 May, 2007 - 10:41 AM
User is offlineProfile CardPM
+Quote Post

horace
RE: Follow Up On Tax Application- Function Structures
10 Mar, 2007 - 01:40 PM
Post #7

D.I.C Addict
Group Icon

Joined: 25 Oct, 2006
Posts: 573



Thanked: 4 times
Dream Kudos: 50
My Contributions
If you did the modifications in my last post you should be passing data from getData() to taxAmount(). You need to check the logic in taxAmount() - note the point that Amadeus made about TAXABLE being 0 so you never calculate Final. I suggest you put some print statements (using cout <<) in taxAmount() so you can see what is the state of variables at each point. You can then see if the values are what you would expect.
User is offlineProfile CardPM
+Quote Post

Phantom_of_the_opera
RE: Follow Up On Tax Application- Function Structures
14 Mar, 2007 - 02:45 PM
Post #8

New D.I.C Head
*

Joined: 13 Nov, 2006
Posts: 43


My Contributions
.

This post has been edited by Phantom_of_the_opera: 3 May, 2007 - 10:41 AM
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Follow Up On Tax Application- Function Structures
14 Mar, 2007 - 03:59 PM
Post #9

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,985



Thanked: 44 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
Merged topics for continuity. Please do not create multiple topics.

Please describe the problem as best you can and include any error messages or descriptions of what your output is currently compared to with what you are expecting it should be.
User is online!Profile CardPM
+Quote Post

Phantom_of_the_opera
RE: Follow Up On Tax Application- Function Structures
15 Mar, 2007 - 05:01 PM
Post #10

New D.I.C Head
*

Joined: 13 Nov, 2006
Posts: 43


My Contributions
.

This post has been edited by Phantom_of_the_opera: 3 May, 2007 - 10:42 AM
User is offlineProfile CardPM
+Quote Post

William_Wilson
RE: Follow Up On Tax Application- Function Structures
15 Mar, 2007 - 05:06 PM
Post #11

lost in compilation
Group Icon

Joined: 23 Dec, 2005
Posts: 4,013



Thanked: 18 times
Dream Kudos: 3275
Expert In: Java, C, Javascript

My Contributions
TAXABLE >= 15001 && TAXABLE <=40000)
pretty sure this should be an or || since the same variable can never be both of those values at once.

*Any change of working in a case of if(name.equals("William Wilson")) { return "tax exempt!"; } ? lol
User is online!Profile CardPM
+Quote Post

Jayman
RE: Follow Up On Tax Application- Function Structures
15 Mar, 2007 - 06:19 PM
Post #12

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,985



Thanked: 44 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
QUOTE(William_Wilson @ 15 Mar, 2007 - 06:06 PM) *

TAXABLE >= 15001 && TAXABLE <=40000)
pretty sure this should be an or || since the same variable can never be both of those values at once.

*Any change of working in a case of if(name.equals("William Wilson")) { return "tax exempt!"; } ? lol

Actually using the AND operand is correct. If you use the OR operand then as long as the first condition is true, it will never evaluate the second condition.


@Phantom_of_the_opera
In your taxAmount method the only place that you assign a value to Final is here:
CODE

if(TAXABLE >= 15001 && TAXABLE <=40000)
{
Total = (TAXABLE - 2250);
cout << Total << endl;
if(Total >15000)
{
  TaxPercent = (Total * .25);
  Final = Total + TaxPercent;
  cout << TaxPercent << endl << Final << endl;
}
}
if(TAXABLE > 40000)
{
Total = (TAXABLE - 8460);
if(Total > 40000)
{
  TaxPercent = (Total * .35);
  Final = Total + TaxPercent;
  cout << TaxPercent << endl << Final << endl;
}


What happens if TAXABLE is 15001 at this point?

Your code enters the first IF statement because it evaluates to true. The first thing you do is put a value in Total equal to (15001 - 2250) = 12751, you then output the value of Total and then enter another IF statement if(Total >15000). Since total is currently 12751 this statement will evaluate to false. The next IF statement will also evaluate to false, if(TAXABLE > 40000). At this point Final has never been assigned a value and as such still has its default value of 0.

I think your second IF statement does not take into account the subtraction of 2250 in the beginning after the first IF statement. Perhaps it should be if(Total >12751).

On a side note, is it possible that TAXABLE can be a value greater 15001 or less then 40000?

If this is the case, it is possible you never get past the first IF statement.
User is online!Profile CardPM
+Quote Post

2 Pages V  1 2 >
Closed TopicStart new topic
Time is now: 12/4/08 03:49PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month