how to get value from function
Apr 5, 2009 at 5:18pm UTC
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;
}
Apr 5, 2009 at 5:38pm UTC
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 Apr 5, 2009 at 5:39pm UTC
Apr 6, 2009 at 6:32am UTC
thanks Gumbercules
Topic archived. No new replies allowed.