c++,定义一个结构体数组,存放三位职工的信息,并计算最高工资及所有职工工资的合计值
结构体里除了工资还要有啥信息呢?光工资也不需要结构体啊
代码如下:
#include <iostream>
#include <string>
using namespace std;
struct Employee
{
string name;
int solary;
};
int main()
{
Employee ep[3];
int sum = 0;
int index = 0;
cout << "请输入3位职工的姓名和工资:" ;
for (int i = 0;i<3;i++)
{
cin >> ep[i].name >> ep[i].solary;
sum += ep[i].solary;
if(i>0 && ep[i].solary > ep[index].solary)
{
index = i;
}
}
cout << "最高工资:" << ep[index].name << " : " << ep[index].solary<<endl;
cout << "合计:"<< sum ;
return 0;
}