I am to design a program that will calculate the bonus an employeewill receive.
ID: 3609393 • Letter: I
Question
I am to design a program that will calculate the bonus an employeewill receive. The program must:*if the number of years worked is valid, determine the amount ofbonus earned by the employee, bonus amount must be rounded to thenearest dollar (round amounts from 01-.49 down and from .50-.99up)
*if the years of employment are valid, display a message thatincludes the employee's initials, annual salary, years of service,and bonus
*if the years of employment value is not valid, display a messagethat includes the employee's initials and states that an invalidlength of employeement was entered
This is my program:
#include <iostream>
#include <iomanip>
using namespace std;
const double Emp_10plus = .12; //12% bonus for employees workingmore than 10 years
const double Emp_5to10 = .05; //5% bonus for employees working 5 to10 years
const double Emp_less_5 = 150.00; /*Flat $150 for employees workingless than 5 years*/
int main()
{
char INITIALS1, INITIALS2;
int YEARS;
double ANNUAL_SALARY;
double BONUS;
cout<<"Please enter employee's initials"<<endl;
cin>> INITIALS1 >>INITIALS2;
cout<<"Please enter years of employment"<<endl;
cin>> YEARS;
cout<<"Please enter annual salary"<<endl;
cin>> ANNUAL_SALARY;
if (YEARS > 10)
{
BONUS = ANNUAL_SALARY * Emp_10plus;
static_cast<int> (BONUS+.5);
}
else
if (YEARS >= 5)
{
BONUS = ANNUAL_SALARY * Emp_5to10;
static_cast<int> (BONUS+.5);
}
else
if (YEARS >= 0)
{
BONUS = Emp_less_5;
}
else
{
cout << INITIALS1 << INITIALS2 <<" # entered foryears of employment "
<<"is not valid"<<endl;
}
cout << fixed << showpoint <<setprecision(2);
cout <<left<<"Employee:"<<right<<setw(12)<<INITIALS1<<INITIALS2<<endl;
cout <<left<<"Years Employed:"<<right<<setw(7)<<YEARS<<endl;
cout <<left<<"Salary:"<<right<<setw(15)<<ANNUAL_SALARY<<endl;
cout<<left<<"Bonus:"<<right<<setw(16)<<BONUS<<endl;
return 0;
}
After compiling and running the program the Bonus should be roundedto the nearest dollar and the decimals should display zeros. Ican't get the zero's to be forced after the decimal.
Also, when I enter an incorrect number of years the program doesnot show the invalid message. Did I write the if..else statementincorrectly?
Please help.
Thanks
Explanation / Answer
//Hope this will help you.. #include #include using namespace std; const double Emp_10plus = .12; //12% bonus for employees workingmore than 10 years const double Emp_5to10 = .05; //5% bonus for employees working 5 to10 years const double Emp_less_5 = 150.00; /*Flat $150 for employees workingless than 5 years*/ int main() { char INITIALS1, INITIALS2; int YEARS; double ANNUAL_SALARY; double BONUS; coutINITIALS2; again: coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.