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;
            }
           
}
mhhoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.