Joshua Ayala Joshua Ayala - 1 month ago 14
C++ Question

C++ calculating salary issue

Hello I am trying to make a program that will calculate an employees bonus when given his salary and job performance, although each time i run the code the bonus is calculated to 1 regardless of the salary I input. and I have to keep my function i created it is part of my homework. Any guidance on what the issue is would be appreciated

#include <iostream>
using namespace std;
double bonus(double salary,int a);
int main()
{
double salary;
enum jobp{poor = 0,average = 1,good = 2};
jobp performance;
int a = performance;
cout<<"Enter your salary and job performance (as a 0 for poor,1 for average and 2 for good)s$
cin>>salary>>a;
bonus(salary,a);
cout<<"your bonus is "<<bonus;
return 0;
}
double bonus(double salary, int a)
{
double bonus;
if (a == 2)
{
double c;
c = .10;
bonus = salary * c;
return bonus;
}
else if (a == 1)
{
double b;
b = .05;
bonus = salary * b;
return bonus;
}
else
{
return 0;
}
}

Answer

Hi this should help you fix your problem. Change this:

cout<<"Enter your salary and job performance (as a 0 for poor,1 for average and 2 for good)s$
cin>>salary>>a;
bonus(salary,a);
cout<<"your bonus is "<<bonus;

To this:

cout << "Enter your salary and job performance (as a 0 for poor,1 for average and 2 for good)" <<endl;
cin >> salary >> a;
cout << "your bonus is " << bonus(salary, a);