c++计算工资问题

C++ calculating salary issue

本文关键字:问题 计算 c++      更新时间:2023-10-16

你好,我试图使一个程序,将计算员工奖金时给予他的工资和工作表现,虽然每次我运行的代码奖金计算为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;
}
}

嗨,这应该能帮你解决问题。改变这个:

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

捕捉返回奖金的值

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

尝试让用户分别输入工资和绩效。

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;