我正在参加在线 C++ 课程,但我很难学习。对于以下问题,我不确定我的代码到底做错了什么。如果小时数 = 40,我的公式是正确的,但如果小时数高于 40 或低于 40,就会出现问题。感谢您的帮助!干杯,R。
Problem:
if hrs <= 40 the regular pay = hrs times pay rate
if hrs > 40 then overtime pay = 1.5 times (hrs - 40) times pay rate
gross pay = regular pay plus overtime pay
// my code
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
//variable declarations
int EmployeeIdentificationNumber = 0;
double Hours = 0;
double PayRate = 0;
double GrossPay = 0;
double RegularPay = 0;
double OvertimePay = 0;
std::cout << "Welcome to the Employee Payroll.\n"; // display message
std:: cout << "Enter Your Employee Identification Number: "; //promp user for data
std::cin >> EmployeeIdentificationNumber; //read integer from user into EmployeeIdentificationNumber
std::cout << "Please enter Hours worked: " ; // prompt user for data
std::cin >> Hours; //read integer from user into Hours
std::cout << "Please enter Pay Rate: " ; // prompt user for data
std::cin >> PayRate; //read integer from user into PayRate
RegularPay = Hours * PayRate; //calculate RegularPay
OvertimePay = 1.5 * (Hours - 40) * PayRate; //Calculate Overtime
//Qualifier for RegularPay
if (Hours <= 40);
RegularPay = Hours * PayRate;
OvertimePay = 0;
GrossPay = RegularPay + OvertimePay;
std::cout << "Gross Pay is = $" ;
//Qualifier for OverTime
if (Hours > 40);
RegularPay = Hours * PayRate;
OvertimePay = 1.5 * (Hours - 40) * PayRate;
GrossPay = RegularPay + OvertimePay;
std::cout << RegularPay + OvertimePay << std::endl;
std::cout << "Thanks for using the Employee Payroll\n";
system("PAUSE");
return EXIT_SUCCESS;
}