help
after running this code why houseRent and commision is showing 0 ? why its not calculating the sum?
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
|
#include<iostream>
using namespace std;
class employee
{
private:
string employeeId;
string name;
string department;
string designation;
float basicSalary;
float commission;
float totalSalesAmount;
float medicalAllowance;
float houseRent;
float totalSalary;
public:
employee()
{
employeeId=" ";
name="";
department="";
designation="";
basicSalary=0.0;
commission=0.0;
totalSalesAmount=0.0;
medicalAllowance=0.0;
houseRent=0.0;
}
employee(string empId,string na,string dep,string desi,float basicsa,float commi,int totalSalesAm,float medical,float house)
{
employeeId=empId;
name=na;
department=dep;
designation=desi;
basicSalary=basicsa;
commission=commi;
totalSalesAmount=totalSalesAm;
medicalAllowance=medical;
houseRent=house;
}
void setDesignation(string d)
{
designation=d;
}
void setDepartment(string de)
{
department=de;
}
void setId(string i)
{
employeeId=i;
}
void setname(string n)
{
name=n;
}
string getName()
{
return name;
}
string getId()
{
return employeeId;
}
void sales()
{
cout<<"Enter the Designation:"<<endl;
cin>>designation;
if(designation=="executive")
{
basicSalary=10000.0;
houseRent=.5*basicSalary;
medicalAllowance=500;
cout<<"Enter His sales amount"<<endl;
cin>>totalSalesAmount;
commission=.2*totalSalesAmount;
totalSalary=basicSalary+houseRent+medicalAllowance+commission;
cout<<"---------------------------------"<<endl;
cout<<"*** Pay Slip ***"<<endl;
cout<<"Employee Name:"<<getName()<<endl;
cout<<"Employee ID:"<<getId()<<endl;
cout<<"Department: Sales"<<endl;
cout<<"Designation : Executive"<<endl;
cout<<"Basic Salary:"<<basicSalary<<endl;
cout<<"House Rent :"<<houseRent<<endl;
cout<<"Medical :"<<medicalAllowance<<endl;
cout<<"Total Sales Amount is:"<<totalSalesAmount<<" Taka"<<endl;
cout<<"commission is:"<<commission<< "taka"<<endl;
cout<<"---------------------------------"<<endl;
cout<<"Total Salary is:"<<totalSalary<< "taka"<<endl;
cout<<"---------------------------------"<<endl;
cout<<"*** End of pay slip ***"<<endl;
}
else
{
basicSalary=20000.0;
houseRent=(60/100)*basicSalary;
medicalAllowance=1000;
cout<<"Enter His sales amount"<<endl;
cin>>totalSalesAmount;
commission=(30/100)*totalSalesAmount;
totalSalary=basicSalary+houseRent+medicalAllowance+commission;
cout<<"---------------------------------"<<endl;
cout<<"*** Pay Slip ***"<<endl;
cout<<"Employee Name:"<<getName()<<endl;
cout<<"Employee ID:"<<getId()<<endl;
cout<<"Department: Sales"<<endl;
cout<<"Designation : Executive"<<endl;
cout<<"Basic Salary:"<<basicSalary<<endl;
cout<<"House Rent :"<<houseRent<<endl;
cout<<"Medical :"<<medicalAllowance<<endl;
cout<<"Total Sales Amount is:"<<totalSalesAmount<<" Taka"<<endl;
cout<<"commission is:"<<commission<< "taka"<<endl;
cout<<"---------------------------------"<<endl;
cout<<"Total Salary is:"<<totalSalary<< "taka"<<endl;
cout<<"---------------------------------"<<endl;
cout<<"*** End of pay slip ***"<<endl;
}
}
};
int main()
{
employee s1;
s1.sales();
}
|
houseRent=(60/100)*basicSalary;
60/100 = 0 becuase both are integers. Same with commision.
thank you ..now i edited like " .6*basicsalary "..
and now the code is running fine :)
Topic archived. No new replies allowed.