c++计算工资问题
C++ calculating salary issue
你好,我试图使一个程序,将计算员工奖金时给予他的工资和工作表现,虽然每次我运行的代码奖金计算为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;
相关文章:
- cpp二进制搜索问题,计算给定数组中输入元素的出现次数
- 代码在我的计算机上运行良好,但是在将其提交给coursera时遇到未知的信号11问题
- C++理解计算字符变量的问题
- 使用指针计算堆栈问题的大 O 表示法
- 使用 cblas_dgemm 计算伪逆的问题
- 我的C++级数计算程序出了什么问题?被困了好几个星期
- 成绩计算问题
- 关于骰子概率计算的一个C++问题
- 我想知道我将如何实现 + 运算符重载.我已经从我上一个问题中计算出 += 运算符重载
- 在 64 位 Linux armv8 计算机上编译 32 位二进制文件时遇到问题
- 在C 中显示小数点,计算问题
- 计算最大成对产品C 的问题
- 优化递归问题以计算超级数字
- 传递数组和计算平均C++的问题
- 冰雹序列C 函数需要计算序列的长度.无限循环问题
- 计算当前日期和用户输入日期问题之间的天数
- 关于 Eigen::MatrixXd 逐列计算的问题
- 谁可以帮助解释我的代码中出了什么问题.计算C ++中的数组
- 在C 中给定范围内计算素数的问题
- 我的逻辑有什么问题?尝试计算文件中包含特定字符的单词数