C++ 构建成功,但不会给出正确的输出
如何让它显示我的结果?顺便说一句,在您的代码中第一次使用structs时,您从未打印出emp的内容,我想这就是您想要实现的 要打印出emp的内容,必须使用以下内容遍历向量: 对于int i=0;iC++ 构建成功,但不会给出正确的输出,c++,C++,如何让它显示我的结果?顺便说一句,在您的代码中第一次使用structs时,您从未打印出emp的内容,我想这就是您想要实现的 要打印出emp的内容,必须使用以下内容遍历向量: 对于int i=0;i
#include <iostream>
#include <fstream>
#include <vector>
#include <iomanip>
using namespace stdd;
struct em
{
int hours;
double payRate;
};
int main()
{
vector<em> emp;
int numEmployees;
int index;
cout << "How Many Employees Do You Have?" << endl;
cin >> numEmployees;
cout << "Enter the hours worked by " << numEmployees;
cout << "employees and their hourly rates.\n";
for (index = 0; index < numEmployees; index++)
{
int tempHours;
double tempRate;
em emp_pay;
cout << "Hours worked by employee #" << (index + 1);
cout << ": ";
cin >> tempHours;
emp_pay.payRate = tempRate;
cout << "Hourly pay rate for employee #";
cout << (index + 1) << ": ";
cin >> tempRate;
emp_pay.payRate = tempRate;
emp.push_back(emp_pay);
}
return 0;
}
How Many Employees Do You Have?
3
Enter the hours worked by 3employees and their hourly rates.
Hours worked by employee #1: 1
Hourly pay rate for employee #1: 10
Hours worked by employee #2: 1
Hourly pay rate for employee #2: 10
Hours worked by employee #3: 1
Hourly pay rate for employee #3: 10
Program ended with exit code: 0.
Employee #{{ employeeNumber }} Hours: {{ hours }} Pay rate: {{ payRate }}