对不起,我知道有人问过类似的问题,但我不理解他们的回答。通常与指针有关,这是我们在课堂上没有学到的。
这是程序
#include <iostream>
using namespace std;
const int NUM_EMPLOYEES = 4;
void readData(string name[NUM_EMPLOYEES], double salary[NUM_EMPLOYEES]);
void updateCOL(double salary[NUM_EMPLOYEES], double COL);
double payroll(double salary[NUM_EMPLOYEES]);
int main()
{
string name[NUM_EMPLOYEES];
double salary[NUM_EMPLOYEES];
double COL;
readData(name, salary);
cout << "Cost of living?" << endl;
cin >> COL;
updateCOL(salary, COL);
for (int i = 0; i < NUM_EMPLOYEES; i++)
{
cout << name[i] << " $" << salary[i] << endl;
}
cout << endl
<< "Total Payroll: $" << payroll(salary) << endl;
return 0;
}
void readData(string name[NUM_EMPLOYEES], double salary[NUM_EMPLOYEES])
{
for (int i = 0; i < NUM_EMPLOYEES; i++)
{
cout << "Name salary? ";
cin >> name[i] >> salary[i];
cout << endl;
}
}
void updateCOL(double salary[NUM_EMPLOYEES], double COL)
{
for (int i = 0; i < NUM_EMPLOYEES; i++)
{
salary[i] = salary[i] + (COL / 100);
}
}
double payroll(double salary[NUM_EMPLOYEES])
{
double payroll = 0;
for (int i = 0; i < NUM_EMPLOYEES; i++)
{
payroll += salary[i];
}
return payroll;
}
预期输入和输出为
Output: Name salary?
Input: John 32000
Output: Name salary?
Input: Jack 56000
Output: Name salary?
Input: Jane 65000
Output: Name salary?
Input: Jill 50000
Output: Cost of living?
Input: 2
Output:
John $32640
Jack $57120
Jane $66300
Jill $51000
Total payroll: $207060
但在最终输出时,我只是在不更新的情况下返回输入。感谢您的提前帮助!
谢谢你们的帮助,这完全是我的公式lmao。