• Status: Solved
• Priority: Medium
• Security: Public
• Views: 205

# C++

the bonus is based on the number of years the employee has been on the company and on his/her performance factor. Employees with performance factor of less than 5, receive no bonus. All other employees receive 1% bonus if they have been working for less than 5 years at the company, and 2% bonus if they have been working for 5 years or over at the company.is there a better way to code rather using the float? or DON'T USE LOOPS OR FUNCTIONS here what I have so far

#include <iostream>

using namespace std;

int main()
{
//declare variables
float employeeSalary = 0.0;
float annualBonus = 0.0;
int yearsEmployed = 0;
int performanceFactor = 0;

//enter employee performance factor, salary, and years employed

cout << " salary:" << endl;
cin >> Salary;
cout << "performance factor:" << endl;
cin >> performanceFactor;
cout << " number of years employed:" << endl;
cin >> yearsEmployed;

//calculate annual bonus

if (performanceFactor < 5)
{
cout << "No annual bonus for employees with less than 5 performance factor" << endl;
}
else if (yearsEmployed < 5)
{
annualBonus = employeeSalary/100;
cout << "The annual bonus for this employee is: " << annualBonus<<endl;
}
else
{
annualBonus = (2*employeeSalary)/100;
cout << "The annual bonus for this employee is: " << annualBonus<<endl;
}

}
0
mhho
• 4
• 3
• 3
2 Solutions

Commented:
hi mhho,

looks good so far. just one thing, the indention in the if-construct

if (performanceFactor < 5)
{
cout << "No annual bonus for employees with less than 5 performance factor" << endl;
}
else
{
if (yearsEmployed < 5)
{
annualBonus = employeeSalary/100;
cout << "The annual bonus for this employee is: " << annualBonus<<endl;
}
else
{
annualBonus = (2*employeeSalary)/100;
cout << "The annual bonus for this employee is: " << annualBonus<<endl;
}
}

ike
0

Author Commented:
I got a complier error using your  indention in the if-construct
0

Author Commented:
regarding  data input validation. I am not familiar with cin.ignore(numeric_limits<streamsize>::max(),'\n') and cin.clear(), your explanation or sample is a great helped
0

Commented:
>> I got a complier error using your  indention in the if-construct
Indentation never gives compilation.
0

Commented:
Your Salary variable is not declared.
0

Commented:
>> I got a complier error using your  indention in the if-construct

please post the error here ...
0

Author Commented:
I made a mistake while complier.    Here is my question:
since the last 2 cout statements are identical, can you use it once for both cases? Iif so how do you do that?
Thanks
0

Commented:
>>  Iif so how do you do that?

if (performanceFactor < 5)
{
cout << "No annual bonus for employees with less than 5 performance factor" << endl;
}
else
{
if (yearsEmployed < 5)
{
annualBonus = employeeSalary/100;
}
else
{
annualBonus = (2*employeeSalary)/100;
}
cout << "The annual bonus for this employee is: " << annualBonus<<endl;
}

ike
0

Author Commented:

#include <iostream>

using namespace std;

int main()

{

//declare variables
float employeeSalary = 0.0;

float annualBonus = 0.0;

int yearsEmployed = 0;

int performanceFactor = 0;

//enter employee performance factor, salary, and years employed

cout << "Enter employee's salary:" << endl;

cin >> employeeSalary;

cout << "Enter employee's performance factor:" << endl;

cin >> performanceFactor;

cout << "Enter number of years employed:" << endl;

cin >> yearsEmployed;

//calculate annual bonus

if (performanceFactor < 5)
{
cout << "No annual bonus for employees with less than 5 performance factor" << endl;
}
else
{
if (yearsEmployed < 5)
{
annualBonus = employeeSalary/100;
}
else
{
annualBonus = (2*employeeSalary)/100;
}
cout << "The annual bonus for this employee is: " << annualBonus<<endl;
}

I got this error below I need help..... urgent...

C:\440>g++ -c 1.cpp
1.cpp: In function `int main()':
1.cpp:61: parse error at end of input
0

Commented:
You forgot to end the main function.

#include <iostream>

using namespace std;

int main()

{

//declare variables
float employeeSalary = 0.0;

float annualBonus = 0.0;

int yearsEmployed = 0;

int performanceFactor = 0;

//enter employee performance factor, salary, and years employed

cout << "Enter employee's salary:" << endl;

cin >> employeeSalary;

cout << "Enter employee's performance factor:" << endl;

cin >> performanceFactor;

cout << "Enter number of years employed:" << endl;

cin >> yearsEmployed;

//calculate annual bonus

if (performanceFactor < 5)
{
cout << "No annual bonus for employees with less than 5 performance factor" << endl;
}
else
{
if (yearsEmployed < 5)
{
annualBonus = employeeSalary/100;
}
else
{
annualBonus = (2*employeeSalary)/100;
}
cout << "The annual bonus for this employee is: " << annualBonus<<endl;
}
} // This need to be added.
0

## Featured Post

• 4
• 3
• 3
Tackle projects and never again get stuck behind a technical roadblock.