c++ - 如何为此代码创建朋友功能?
问题描述
我想创建一个朋友功能来显示三名员工中获得最高薪水的员工。我不确定该怎么做。我的代码已经可以工作了,只是想添加它。执行此操作的代码是什么,为什么会起作用?我正在查看其他人的工作示例,但它们对我来说真的没有意义。我希望你能帮忙。谢谢!
#include <iostream>
using namespace std;
double Pay(double rate, double hours);
struct StaffInfo {
int Staff_ID;
double Hourly_Rate;
double Weekly_Hours;
int Dep_Num;
double Paid;
int Birth_Year;
};
int main()
{
// # of Staff members
StaffInfo staff[3];
// For loop to get user input for the 3 staff members
for (int i = 0; i < 3; i++) {
cout << "Staff ID: ";
cin >> staff[i].Staff_ID;
cout << "Hourly Rate: ";
cin >> staff[i].Hourly_Rate;
cout << "Hours worked: ";
cin >> staff[i].Weekly_Hours;
cout << "Department Number: ";
cin >> staff[i].Dep_Num;
cout << "Birth Year: ";
cin >> staff[i].Birth_Year;
cout << endl;
//Calls Pay function
staff[i].Paid = Pay(staff[i].Hourly_Rate, staff[i].Weekly_Hours);
}
//Prints Staff# and how much they got paid
for (int i = 0; i < 3; i++) {
cout << endl << "Staff #:" << staff[i].Staff_ID << " pay is: $" << staff[i].Paid << endl;
}
}
// Determine how much staff member gets paid
double Pay(double rate, double hours)
{
double PayCheck = 0;
//Determines if they worked overtime or not
if (hours >= 40.00)
{
//Overtime pay rate
PayCheck = ((rate * 1.5) * hours);
}
else if (hours < 40.00)
{
//No Overtime
PayCheck = (rate * hours);
}
return PayCheck;
}
解决方案
推荐阅读
- .net-core - UWP 和 .NetCore - 不一致的字体系列名称
- android - Firestore 安全规则仅允许访问特定查询而不是整个集合
- ruby-on-rails - 安装 pg (1.2.3) 时出错,Bundler 无法继续
- label - 不能在新的自定义程序中使用标签
- azure - Azure Function App Cosmos DB 触发连接断开
- javascript - 在onload javascript中禁用回车
- amazon-web-services - 从 Fargate 容器发出的 API 调用需要根据证书进行验证。在这种情况下,我可以将证书放在哪里?
- python - Matplotlib 加速将绘图保存到磁盘
- java - 用于在 JSON 文档中搜索特定路径的 MarkLogic Java API
- docker - 启动 docker 容器时所需的密钥不可用