C++ C++;加班/工资单/工时半/双倍

C++ C++;加班/工资单/工时半/双倍,c++,visual-c++,C++,Visual C++,我知道我的if语句在某个地方不正确,但我不知道在哪里?或者只是逻辑上的错误 8小时后,任何工作时间都将获得一个半小时的工资。也就是说,假设每小时工资乘以1.5。工资是8小时后支付的 10小时后,工作时间将加倍支付。也就是说,假设每小时工资乘以2.0。工资是10小时后支付的。 请显示:(示例输出) 每小时工资:12.37 工作时间:10.3小时 支付(0至8小时):98.96 支付工作时间(8至10小时):37.11 按小时付费(10小时及以上):7.42 工资总额:143.49 // Examp

我知道我的if语句在某个地方不正确,但我不知道在哪里?或者只是逻辑上的错误

8小时后,任何工作时间都将获得一个半小时的工资。也就是说,假设每小时工资乘以1.5。工资是8小时后支付的

10小时后,工作时间将加倍支付。也就是说,假设每小时工资乘以2.0。工资是10小时后支付的。 请显示:(示例输出)

每小时工资:12.37 工作时间:10.3小时

支付(0至8小时):98.96

支付工作时间(8至10小时):37.11

按小时付费(10小时及以上):7.42

工资总额:143.49

// Example program
#include <iostream>
#include <string>

using namespace std;

double HoursWorked;
double WagePerHour;
double TotalWages;
double TimeAndHalf;
double Overtime;
char ContinueChar;

//test cases: 10.5 hours @ 12/hour = $96.00, 2 hours at 1.5 rate = $36.00, .5 hour at 2.0 rate = $12.00
// 6.3 hours @ 12/hour = 75.6, no hours of overtime or double time
//12.5 hours @ 14.34/ hour = $114.72, 2 hours at 1.5 rate = 43.02, 2.5 hours at 2.0 rate = $71.70
//3.7 hours @ 19/hour = $70.30
// 14 hours @ 23.50/hour = $188, 2 hours at 1.5 rate = $70.50, 4 hours at 2.0 rate = $188
//I tested with test test cases and the program had the same results.

int main()
{

    cout << "Ticket #64220\n";
    cout << "CMPR-120\n";
    cout << "Instructor : Joel Kirscher\n";
    cout << "Student: Seyed Shariat\n";
    cout << "Payroll Overtime";
    cout << "\n\n";



    do {
        cout << "How many hours did you work this pay period: \n";
        cin >> HoursWorked;
        cout << "What wage do you get paid per hour?: \n";
        cin >> WagePerHour;
        cout << "So you your paycheck will be: " << HoursWorked * WagePerHour << " before taxes are taken out. \n";

        if (HoursWorked > 8 && <= 10)
            cout << "For the hours you worked over 8, and less than or equal to 10 you made: " << HoursWorked * 1.5 * WagePerHour << " \n";
        else (HoursWorked >10);
        cout << "For the hours you worked over 10: " << HoursWorked * 2.0 * WagePerHour << " \n";

        cout << "Do you want this to run again? (y=Yes): ";
        cin >> ContinueChar;
    } while (ContinueChar == 'y' || ContinueChar == 'Y');


    cin.get();

    return 0;
}
//示例程序
#包括
#包括
使用名称空间std;
工作两小时;
每小时双倍下注;
双倍工资;
双倍半;
双倍加班;
煤焦;
//测试用例:12小时时10.5小时=96.00美元,1.5小时费率=36.00美元,2.0小时费率=12.00美元
//12小时/6.3小时=75.6小时,无加班或双倍工作时间
//12.5小时@14.34/小时=114.72美元,2小时1.5费率=43.02美元,2.5小时2.0费率=71.70美元
//19小时时的3.7小时=70.30美元
//每小时23.50美元时的14小时=188美元,1.5美元时的2小时=70.50美元,2.0美元时的4小时=188美元
//我用测试用例进行了测试,程序得到了相同的结果。
int main()
{

有很多方法可以解决这个问题。这里有一个。这些评论可以帮助你理解我的推理。幸运的是,这背后的数学不是很复杂

/*
We need to find the area under this pay rate / hours worked graph.
The following approach divides the graph into three rectangles as shown below
2.0 |         +--+
    |         |  |
1.5 |       +-+--|
    |       |    |
1.0 +-------+----|
    |            |
0.5 |            |
    |            |
0.0 +------------+
    0       8 10
*/
// Calculate basic pay before any overtime consideration
Pay = HoursWorked * HourlyRate;

// Hours above 8 earn half-again more than the standard wage.
// (This will be only positive if more than 8 hours were worked.)
OvertimePay = (HoursWorked - 8.0) * HourlyRate * 0.5;
if(OvertimePay > 0.0)
    Pay += OvertimePay;

// Hours above 10 earn an additional 50% extra
// (This will be only positive if more than 10 hours were worked.)
OvertimePay = (HoursWorked - 10.0) * HourlyRate * 0.5;
if(OvertimePay > 0.0)
    Pay += OvertimePay;

我知道我的if语句在某些地方是不正确的,但我不知道它是哪里的逻辑错误?这可能是调试器所需要的。因为这是标记的VisualC++,您可以访问一个好的调试器,它允许您单步通过代码,查看每个步骤的变量,以查看代码出现在哪里的执行方式不同。从您的期望值中选出。示例输出为您提供了一个关于如何解决该问题的很好的线索。它首先考虑前八个小时,然后考虑下两个小时,然后再考虑任何超过10个小时的时间,然后将这三个小时相加得出一个总数。您的方法似乎试图根据总工作小时数从三个不同的课程中选择一个。我建议这一点更容易理解,不是“A或B或C中的一个适用于本案”,而是“A可能适用,如果适用,B也可能适用,如果适用,C也可能适用”提示:
int hoursbevent=hoursweard-8;
对于每个部分,您需要计算出需要支付的小时数。第一部分是0到8之间的数字。您需要确保它不超过8。对于第二部分(时间半)你需要一个介于0和2之间的数字。将这两个小时的工资与前8个小时的工资相加。对于最后一部分……最高工资是多少?可能超出了问题的范围。无论如何,不管他们在10小时以上工作了多少小时,都要为他们支付双倍的工资。问题是你计算的时间和双倍工资的时间太多了我。你不使用HoursWorked,因为这是总小时数。这更像是一个数学问题,而不是一个编程问题。