gpt4 book ai didi

C++ 任务不正确的结果

转载 作者:太空宇宙 更新时间:2023-11-04 15:22:24 25 4
gpt4 key购买 nike

题目如下

写一个程序,提示用户输入一个员工的每小时工资,本周工作的小时数,并计算出他的周薪。如果他工作超过40小时,超过40小时,每小时工资是原工资的1.5倍。从工资总额中抽取6%的社保税,14%的所得税,10欧元的 union 。如果员工有 2 个以上的 child ,他将支付 35 欧元的健康保险。计算他的周薪。

我的代码

#include "stdafx.h"
#include "iostream"
using namespace std;

int main()
{
double a,b,c,kid;
cout << "Enter his salary per hour: " << endl;
cin >> a;
cout << "Enter the amount of hours he worked this week: " << endl;
cin >> b;
cout << "How many kids does he have: " << endl;
cin >> kid;

if ( a > 40 ) {
if (kid > 2) {
b = (b-40)*1.5+40;
c = a*b-a*b*20/100-10-35;
}
else {
b = (b-40)*1.5+40;
c = a*b-a*b*20/100-10;
}
}
else {
if (kid > 2)
c = a*b-a*b*20/100-10-35;
else
c = a*b-a*b*20/100-10;
}

cout << c;
system("pause");
return 0;
}

我编写的代码没有给出正确的结果。哪里错了?

最佳答案

你不应该使用单字母的、无意义的变量名。否则你会注意到错误:

if ( a > 40 )

你想比较小时数,但你确实比较了工资。

关于C++ 任务不正确的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15859288/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com