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

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
Asked:
mhho
  • 4
  • 3
  • 3
2 Solutions
 
ikeworkCommented:
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
 
mhhoAuthor Commented:
I got a complier error using your  indention in the if-construct
0
 
mhhoAuthor 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
rajeev_devinCommented:
>> I got a complier error using your  indention in the if-construct
Indentation never gives compilation.
You added or removed something.
0
 
rajeev_devinCommented:
Your Salary variable is not declared.
0
 
ikeworkCommented:
>> I got a complier error using your  indention in the if-construct

please post the error here ...
0
 
mhhoAuthor 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
 
ikeworkCommented:
>>  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
 
mhhoAuthor 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
 
rajeev_devinCommented:
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

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

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