Link to home
Start Free TrialLog in
Avatar of mhho
mhho

asked on

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;
            }
           
}
Avatar of ikework
ikework
Flag of Germany image

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
Avatar of mhho
mhho

ASKER

I got a complier error using your  indention in the if-construct
Avatar of mhho

ASKER

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
>> I got a complier error using your  indention in the if-construct
Indentation never gives compilation.
You added or removed something.
Your Salary variable is not declared.
>> I got a complier error using your  indention in the if-construct

please post the error here ...
Avatar of mhho

ASKER

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
SOLUTION
Avatar of ikework
ikework
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mhho

ASKER


#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
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial