【发布时间】:2012-02-01 08:39:42
【问题描述】:
我必须创建一个循环来从员工的用户输入中收集所有信息。如您所见,我已经获得了询问用户有多少员工以及他们的信息是什么的部分。现在我所要做的就是像这样将这些信息打印到屏幕上,只是没有每个之间的句点,每个之间有几个空格:
Weekly Payroll:
Name...............Title........Gross.......Tax.........Net
----------------------------------------
Ebenezer Scrooge.....................Partner...250.00......62.25.....187.75
Bob Cratchit...............................Clerk.......15.00........2.00.......13.00
这就是我所拥有的:
#include <iostream>
using namespace std;
const int MAXSIZE = 20;
struct EmployeeT
{
char name[MAXSIZE];
char title;
double SSNum;
double Salary;
double Withholding_Exemptions;
};
EmployeeT employees[MAXSIZE];
int main()
{
cout << "How many Employees? ";
int numberOfEmployees;
cin >> numberOfEmployees;
while(numberOfEmployees > MAXSIZE)
{
cout << "Error: Maximum number of employees is 20\n" ;
cout << "How many Employees? ";
cin >> numberOfEmployees;
}
char name[MAXSIZE];
int title;
double SSNum;
double Salary;
double Withholding_Exemptions;
for (int count=0; count < numberOfEmployees; count++)
{
cout << "Name: ";
cin >> employees[ count ].name;
cout << "Title: ";
cin >> employees[ count ].title;
cout << "SSNum: \n";
cin >> employees[ count ].SSNum;
cout << "Salary: \n";
cin >> employees[ count ].Salary;
cout << "Withholding Exemptions: \n";
cin >> employees[ count ].Withholding_Exemptions;
}
double gross;
double tax;
double net;
double adjusted_income;
gross = employees[ count ].Salary;
adjusted_income = employees[ count ].Salary - 1.00;
tax = adjusted_income * .25;
net = gross - tax;
cout << "Weekly Payroll:\t Name \t Title \t Gross \t Tax \t Net \n";
for (int count=0; count < numberOfEmployees; count++)
{
cout << employees[count].name << " \t" << employees[count].title << " \t" <<
gross << "\t" << tax << "\t" << net << "\n";
}
system("pause");
}
好的,我更新了程序。现在我正在尝试进行计算。这就是我正在做的......
计算工资:
总工资是之前为员工输入的周薪。
净工资的计算方法是总工资减去税额。
计算税款:从工资中扣除每笔预扣税减免 1 美元。这是调整后的收入。如果调整后的收入小于 0,则使用 0 作为调整后的收入。
将调整后的收入乘以税率,您应该假设税率为 25%。
例如,如果 Bob Cratchit 的周收入为 15 美元,并且有 7 个受抚养人,那么他的调整后收入将为 8 美元。他的税是 8 美元的 25%,即 2 美元,因此他的净收入是 13 美元。
我已经开始尝试得到这个。我把它放在第二个循环和最后一个循环之间。是这样吗?
【问题讨论】:
-
请更具体。究竟是什么不起作用。你试过什么?如果您发布代码,请将其减少到证明您的问题所需的最低限度。例如,由于这个问题是关于程序的输出的,所以用一些硬编码数据替换从用户那里获取输入的部分,因为它不相关。有关如何编写好的代码示例的更多信息,请参阅sscce.org。