how to get value from function

i wrote like this
this is not giving me any error
but ist crashing off course
i know i couldnt pass the value from function to main.
can any body help meeeeeeeeeeeee!!!!!

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
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<string>
using namespace std;


void getIncomeTax(int salary)
{int tax;
	tax=((salary * 25)/100);
	
}

void main()
{
	double salary, allowances, incomeTax;
char name[30];
string Name;
int netpay;

 cout<<"Enter Persons Name :";
 getline(cin, Name);
 cout<<endl;

 cout<<"Enter Salary: ";
 cin>>salary;
 cout<<endl;

 cout<<"Enter Allowances: ";
 cin>>allowances;
 cout<<endl;
int tax;
 system("cls");
 getIncomeTax(tax);
 netpay=(salary - tax)+allowances;


 cout<<"\nPerson Name"<<setw(15)<<"Salary"<<setw(14)<<"Tax"<<setw(15)<<"net pay"<<endl<<endl;
 cout<<Name<<setw(10)<<salary<<setw(10)<<allowances<<tax<<setw(10)<<netpay<<endl<<endl<<endl;

 
}
You can have it return a value by making the function like :
1
2
3
4
int getIncomeTax(int salary)
{
	return (salary * 25)/100;
}

then use it like:
int tax = getIncomeTax(salary);
Last edited on
thanks Gumbercules
Topic archived. No new replies allowed.