(Pardon my english) So im new at coding. the main problem on my program is that when I multiply a variable with another variable, it just doesn't work. here is the full program.
#include <iostream>
using namespace std;
class employment {
private:
// Private attribute
int salary;
public:
// Setter
void setSalary(int s) {
salary = s;
}
// Getter
int getSalary() {
return salary;
}
};
void divider(int y){
for(int i=1;i<y; i++){
cout<<"=============================\n";
}
}
int main() {
string name,category, status;
char penalty,i;
int penaltyAm, categoryAm;
//Regional division
employment regionalDiv;
regionalDiv.setSalary(5000000);
//Administration and warehousing
employment adminWarehouse;
adminWarehouse.setSalary(5700000);
//Factory manager
employment factManager;
factManager.setSalary(15000000);
//Marketing manager
employment marketManager;
marketManager.setSalary(16000000);
//Personnel manager
employment persManager;
persManager.setSalary(18000000);
// Other manager
employment otManager;
otManager.setSalary(25000000);
//Personnel director
employment persDirector;
persDirector.setSalary(35000000);
//Other director
employment otDirector;
otDirector.setSalary(40000000);
//Director of finance
employment finDirector;
finDirector.setSalary(45000000);
//President director
employment presDirector;
presDirector.setSalary(50000000);
//Director
employment director;
director.setSalary(60000000);
do{
//asking for employment category
divider(3);
cout<< "Name: ";
getline(cin,name);
cout<< "employment category: ";
getline(cin, category);
categoryAm=0;
if(category=="Regional division"){
cout<< "Salary: "<<regionalDiv.getSalary()<<endl;
categoryAm= 5000000;
}
else if(category=="Administration and warehousing"){
cout<< "Salary: "<<adminWarehouse.getSalary()<<endl;
categoryAm= 5700000;
}
else if(category=="Factory manager"){
cout<< "Salary: "<<factManager.getSalary()<<endl;
categoryAm= 15000000 ;
}
else if(category=="Marketing manager"){
cout<< "Salary: "<<marketManager.getSalary()<<endl;
categoryAm= 16000000;
}
else if(category=="Personnel manager"){
cout<< "Salary: "<<persDirector.getSalary()<<endl;
categoryAm= 18000000;
}
else if(category=="Other manager"){
cout<< "Salary: "<<otManager.getSalary()<<endl;
categoryAm= 25000000;
}
else if(category=="Personnel director"){
cout<< "Salary: "<<persDirector.getSalary()<<endl;
categoryAm= 35000000;
}
else if(category=="Other director"){
cout<< "Salary: "<<otDirector.getSalary()<<endl;
categoryAm= 40000000;
}
else if(category=="Director of finance"){
cout<< "Salary: "<<presDirector.getSalary()<<endl;
categoryAm= 45000000;
}
else if(category=="President director"){
cout<< "Salary: "<<presDirector.getSalary()<<endl;
categoryAm= 50000000;
}
else if(category=="Director"){
cout<< "Salary: "<<director.getSalary()<<endl;
categoryAm= 60000000;
}
cout<<"Penalty(T/F): ";
cin>> penalty;
if(penalty=='T'){
cout<<"Amount of penalty(%): ";
cin>>penaltyAm;
penaltyAm=100-penaltyAm;
// cout<<penaltyAm<<endl;
// cout<<categoryAm<<endl;
int moSalary=categoryAm*penaltyAm/100;
cout<<"This month salary: "<<moSalary<<endl;
}else{
cout<<"This month salary: "<<categoryAm<<endl;
}
cout<<"Status :";
cin>>status;
divider(2);
cout<<"new data(Y/N) :";
cin >> i;
cin.ignore ();
}while(i=='Y');
return 0;
}
the problem occurs here
cout<<"This month salary: "<<moSalary<<endl;
cin category variable as "Regional division" (aka first if) it just works well.
but when i cin category variable with other than "Regional division", the moSalary variable turned to minus something and that's illogical. Anyway i don't understand the way company works. this is just my excercise.
i tried to change moSalary declaration places but it still fails.
i hope someone can help me to make the moSalary variable works well.
tried 1:
so this is how the program went please look at the "This month salary:.."
when I inputed "Personnel director", it should set categoryAm= 5000000
.
and I set penalty to Y, means that I should enter the penalty number in percent. i inputed penaltyAm = 10
. then I assigned penaltyAm to 100-penaltyAm that is 90 so I can multiply it later.
it should be good but then the output of int moSalary=categoryAm*penaltyAm/100;
became
minus and I don't understand why.
tried 2: I tried to change moSalary type data into float. it become more confusing for me as I don't have basic knowledge of it. 1.44e+007 what TvT help :"
tried 3:
so I tried adding #include<stdint.h>
and changing moSalary data type into int64_t
and it produced minus number again. Is there anything else I can try? thank you.