C ++任务结果不正确

时间:2013-04-07 05:40:53

标签: c++

问题如下

写一个程序,提示用户输入员工每小时的工资,当前工作小时数,并计算他的周薪。如果他的工作时间超过40小时,他每小时的工资是每小时超过40小时的原始工资的1.5倍。从工资总额中,6%用于社会保障税,14%用于所得税,10欧元用于工会。如果该员工有2个以上的孩子,他需要支付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;
}

我制作的代码并没有给我正确的结果。哪里错了?

1 个答案:

答案 0 :(得分:7)

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

if ( a > 40 )

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