C ++计算工资问题

时间:2016-10-21 01:47:05

标签: c++ enums

您好我正在尝试制作一个程序,在计算员工奖金时给出他的工资和工作绩效,尽管每次运行代码时奖金计算为1,无论我输入的薪水如何。我必须保持我创建它的功能是我作业的一部分。任何有关问题的指导都将受到赞赏

#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;
}
}

3 个答案:

答案 0 :(得分:0)

您好,这可以帮助您解决问题。 改变这个:

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;

对此:

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);

答案 1 :(得分:0)

抓住退回奖金的价值

#include <iostream>
using namespace std;
double bonus(double salary,int a); //this is for function right?
int main()
{
    double salary;
    double bonus; //create a variable for bonus
    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 = bonus(salary,a); //catch the return
    cout<<"your bonus is "<<bonus;
    return 0;
}

答案 2 :(得分:0)

尝试让用户单独输入薪水和表现。

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