converting to Function

Hi
i wrote this program
but i want to tranfer
to a function
and i have no idea how to do it

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


//declare headerfiles

#include<iostream>
#include<string>
#include<iomanip>

void getData();

using namespace std;

char marital_status;

int main(){
	string name;
	
	double grossAmount=0.0, pensionPlan, netPay=0.0, federal_taxes=0.0;
	double person_exemption = 1500.00;
	double exemption;
	double number_of_children=0;

	cout<<"Enter your name : ";
	getline(cin, name);


	getData();
	if ( marital_status == 's' ){
		exemption = 4000.00 + person_exemption;
	
		cout<<"\nPlease enter the Gross amount salary: ";
		cin>> grossAmount;

		cout<<"\nEnter percentage of gross income contributed to a pension fund (enter 0 if there is not contribution): ";
		cin>>pensionPlan;
		pensionPlan = pensionPlan / 100;
		
		netPay = grossAmount - (grossAmount*pensionPlan) - exemption;
	}//end s if statement


	else
	if ( marital_status == 'm' ){
		exemption = 7000.00;
		cout<<"\nPlease enter both, yours and spouse Gross salary combined: ";
		cin>> grossAmount;

		cout<<"Please how many children do you have? ( 0 for if you dont have any kids): ";
		cin>>number_of_children;
		exemption = exemption + ( (2 + number_of_children) * person_exemption);

		cout<<"\nEnter percentage of gross income contributed to a pension fund (enter 0 if there is not contribution): ";
		cin>>pensionPlan;
		pensionPlan = pensionPlan / 100;
		netPay = grossAmount - (grossAmount*pensionPlan) - exemption;
	}//end s if statement


	
	if ( netPay<=15000){
		federal_taxes = 0.15;
			federal_taxes = federal_taxes * netPay;

	}

		
	else

	if (netPay<= 40000){
		federal_taxes = 0.25;
			federal_taxes = federal_taxes * netPay + 2250;

	}

		
	else

	if (netPay > 40000){
		federal_taxes = 0.35;
			federal_taxes = federal_taxes * netPay + 8460;

	}

	cout<<endl;
	cout<< fixed << showpoint << setprecision(2);
	cout<<name<<", your Net pay is : "<< netPay;
	cout<<"\nYour Federal Taxes owe is : "<< federal_taxes<<endl;





	return 0;
system ("pause");
}//end main


void getData(){

		cout<<"Are you single or married? (s for single -- m for married): ";
	cin>> marital_status;


}


Last edited on
i guess no help lol
What is it you want to transfer to a function?
You already have getData as a function (albeit not a particularly useful example of one).

If you are unsure, try thinking of how you want the program to work in logical chunks (ignore the code at this point).
EG
1) Check if Married or Single
2) Enter Salary, Pension & Children as applicable to marital status.
3) Calculate Taxes
Which would indicate 3 functions as a starting point.
Entering the Salary, Pension & Childern could then be split into separate functions called as required to avoid duplication, etc.

Once you know what you want you cna try coding it, and ask if you are stuck on a particular problem.
Topic archived. No new replies allowed.