holding values from other functions?

Ok so im confused because when I call a function on its own the decimal is kept, but when I call the display function it no longer displays the correct decimal just .00
I put the code below, i only included one function because otherwise it would be a lengthy post. Any help would be appreciated even if it is just a suggested search term to go read the info i am missing.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57

int getActualTax()
{
   double actTaxesWithheld ;
   cout << "\tYour actual taxes withheld: " ;
   cin >> actTaxesWithheld ;
   return actTaxesWithheld ;
}

int display()
{
   cout.setf(ios::fixed) ;
   cout.setf(ios::showpoint) ;
   cout.precision(2) ;

   double income = getIncome() ;
   double budgetLiving = getBudgetLiving() ;
   double actualLiving = getActualLiving() ;
   double actTaxesWithheld = getActualTax() ;
   double actualTithing = getActualTithing() ;
   double actualOther = getActualOther() ;
   double lawOfTithe = income * (0.1) ;
   double budgetOther = income - budgetLiving - lawOfTithe ;

   double actualDifference = income - actualLiving - lawOfTithe - actTaxesWithheld
      - actualOther ;
   double budgetDifference =  0.00 ;

   cout << "\n" ;
   cout << "The following is a report on your monthly expenses\n"
        << "\tItem" << setw(24) << "Budget" << setw(16) << "Actual" << "\n"
        << "\t===============" << " " << "===============" << " "
        << "===============\n" ;
   cout << "\tIncome" << setw(11) << "$" << setw(11) << income << setw(5)
        << "$" << setw(11) << income * 1.00 << "\n" ;
   cout << "\tTaxes" << setw(12) << "$" << setw(11) << 0.00 << setw(5)
        << "$" << setw(11) << actTaxesWithheld << "\n" ;
   cout << "\tTithing" << setw(10) << "$" << setw(11) << lawOfTithe << setw(5)
        << "$" << setw(11) << actualTithing << "\n" ;
   cout << "\tLiving" << setw(11) << "$" << setw(11) << budgetLiving
        << setw(5) << "$" << setw(11) << actualLiving << "\n" ;
   cout << "\tOther" << setw(12) << "$" << setw(11) << budgetOther << setw(5)
        << "$" << setw(11) << actualOther << "\n" ;
   cout << "\t===============" << " " << "===============" << " "
        << "===============\n" ;
   cout << "\tDifference" << setw(7) << "$" << setw(11) << budgetDifference << setw(5)
        << "$" << setw(11) << actualDifference << "\n" ;

   return 0 ;
}

int main()
{
   cout << "This program keeps track of your monthly budget\n" ;
   cout << "Please enter the following:\n" ;
   cout << display() ;
}

Last edited on
I'm not sure I understand. Could you provide an example of the actual program output and then the expected or required output for comparison.

(use the [output]results here[/output] tags to display properly formatted.
yeah, so

basically i ask the user for inputs to make a budget and then display the inputs in a table of sorts
my initial function should look like this :

Your actual taxes withheld: 502.12 (user inputs- 502.12)

this works correctly.

but then in the display() it makes a table like this

budgeted actual
====== ======
502.00 502.00


the issue is that it drops the .12 and i cant figure out why.

Last edited on
The value is getting narrowed to int
1
2
3
4
5
6
7
8
// int getActualTax()
double getActualTax()
{
   double actTaxesWithheld ;
   cout << "\tYour actual taxes withheld: " ;
   cin >> actTaxesWithheld ;
   return actTaxesWithheld ;
}
wow thank you so much! no wonder I couldn't even search correctly on google for an answer.
Topic archived. No new replies allowed.