//declare headerfiles
#include<iostream>
#include<string>
#include<iomanip>
void getData();
usingnamespace 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
elseif ( 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;
}
elseif (netPay<= 40000){
federal_taxes = 0.25;
federal_taxes = federal_taxes * netPay + 2250;
}
elseif (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;
}
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.