Help with functions

Hi guys!
I am having trouble with returning information from my function.
How can I return multiple variable from my function into the main? ( the function is called: calcFederalTax
and I want to return:
annualTaxableIncome
percentTaxRate
taxRate
federalIncomeTax
weeklyFederalIncomeTax

Here is my code:
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

//function prototypes 
double readDoubleBetween(string, double, double);
double calcWage(double, double);
double calcFicaTax (double);
double calcFederalTax (double);

int main ()
{
    //constant section
    const double FED_MINIMUM_WAGE = 7.25;  //minimum federal wage
    
    //variable section
    double hours      = 0.0;    //hours worked during the week. 
    double hourlyRate = 0.0;    //hourly rate of pay
    double weeklyWage = 0.0;    //weekly wage
    double ficaTax    = 0.0;    //fica tax
    double weeklyFederalIncomeTax = 0.0; // Federal Income Tax
    
    //set print options
    cout << fixed << showpoint << setprecision(2);
        
    //print heading
    cout << "Program to calculate weekly gross pay for hourly employees" << endl;
    cout << "With deductions for FICA and Federal Income Tax" << endl;
    
    //read hours between 0 and 40
    hours = readDoubleBetween("Enter hours worked: ", 0.0, 40.0);      
    
    
    //read hourly rate between federal minimum wage of 7.25 and 25.00
    //call function here
    hourlyRate = readDoubleBetween("Enter hourly rate: ", 7.25, 25.00);  
                         
                            
    //calculate weekly wage
    //call function here
    weeklyWage = calcWage( hours, hourlyRate);
    
    //calculate FICA tax at the rate of 7.65%
    //call function here
    ficaTax = calcFicaTax(weeklyWage);
    
    //Calculate the Weekly Federal Income Tax
    //call function here
    weeklyFederalIncomeTax = calcFederalTax(weeklyWage);
    
    
    
    
    
    
    
    
    
    
    
    //print gross wage
    cout << endl;
   
    cout << left << setw(22) << "Taxable Income: " << annualTaxableIncome << endl;
    cout << left << setw(22) << "Annual Tax at " << percentTaxRate << "% rate: " << federalIncomeTax << endl << endl;
    
    cout << left << setw(13) << "Gross Wage"  << right << setw(8) << weeklyWage << endl;
    cout << left << setw(13) << "FICA Tax"    << right << setw(8) << ficaTax << endl;
    cout << left << setw(13) << "Federal Tax" << right << setw(8) << weeklyFederalIncomeTax << endl;
      
    //freeze console window
    cout << endl;
    system("Pause");
    return 0;  
} //end main


//-------------------------------------
//Name: readDoubleBetween
//Purpose: read a double between two given values
//Parameters:
//  prompt - user prompt
//  lowValue - lowest acceptable value
//  highValue - highest acceptable value
//Returns: number between lowValue and highValue, inclusively
//-------------------------------------
double readDoubleBetween(string prompt, double lowValue, 
                                        double highValue)
{
   double numbers = 0.0;
   cout << prompt;
   cin >> numbers;
   while ( numbers < lowValue || numbers > highValue)
   {
     cout << "      Invalid input - must be between " << lowValue << " and " << highValue << endl;
     cout << prompt;
     cin >> numbers;    
   }
   return (numbers);
}


//-------------------------------------
//Name: calcWage
//Purpose: Calculate weekly wage
//Parameters: hours and hourly wage
//Returns: weeklyWage
//-------------------------------------

double calcWage(double hours, double hourlyRate)
{
    
    double weeklyWage  = hours * hourlyRate;
    return weeklyWage;  
    
}


//-------------------------------------
//Name: calcFicaTax
//Purpose: Calculate FICA Tax
//Parameters: weeklyWage
//Returns: ficaTax
//-------------------------------------

double calcFicaTax(double weeklyRate)
{
    const double FICA_TAX = 7.65 / 100 ;  //FICA TAX RATE
    double ficaTax  = weeklyRate * FICA_TAX;
    return ficaTax;  
    
}

//-------------------------------------
//Name: calcFederalTax
//Purpose: Calculate Federal Income Tax
//Parameters: weeklyWage
//Returns: weeklyFederalIncomeTax
//-------------------------------------

double calcFederalTax(double weeklyRate)
{
    double federalIncomeTax = 0.0;
    double percentTaxRate = 0.0;
    double taxRate       = 0.0;
    double weeklyFederalIncomeTax = 0.0;
    const double STANDARD_DEDUCTION = 5800 ;  //Standard single filer deduction  
    double annualTaxableIncome = ( weeklyRate * 52 ) - STANDARD_DEDUCTION;
    
    if (annualTaxableIncome <= 8500)
    {
       percentTaxRate = 10;
       taxRate = percentTaxRate / 100
       federalIncomeTax = taxRate * annualTaxableIncome;
       weeklyFederalIncomeTax = federalIncomeTax / 52;
        
    }
    
    elseif (annualTaxableIncome > 8500 && annualTaxableIncome  < 34500)
    {
       percentTaxRate = 15;
       taxRate = percentTaxRate / 100;
       federalIncomeTax = 850 + taxRate * (annualTaxableIncome - 8500);
       weeklyFederalIncomeTax = federalIncomeTax / 52;
        
    }
    
    else
    {
        percentTaxRate = 25;
        taxRate = percentTaxRate / 100;
        federalIncomeTax = 4750 + taxRate * (annualTaxableIncome - 34500);
        weeklyFederalIncomeTax = federalIncomeTax / 52;
        
    }
    return weeklyFederalIncomeTax;  
    
}




define a structure that contains them, then return the structure or structure's pointer from that function.
Topic archived. No new replies allowed.