C++ 计算无需处理C++;
我正在做一个简单的工资计算器,由于某种原因,我的“税”无法计算。当我运行程序时,它们只在输出中显示$0。知道是什么引起的吗?我注释了“//未计算。在未计算的行上显示$0”C++ 计算无需处理C++;,c++,C++,我正在做一个简单的工资计算器,由于某种原因,我的“税”无法计算。当我运行程序时,它们只在输出中显示$0。知道是什么引起的吗?我注释了“//未计算。在未计算的行上显示$0” #include <iostream> using namespace std; int main() // Parameters: None // Returns: Zero // Calls: None { int const hourly_wage = 16.78, overtime_rat
#include <iostream>
using namespace std;
int main()
// Parameters: None
// Returns: Zero
// Calls: None
{
int const hourly_wage = 16.78, overtime_rate = 25.17, social_security = 0.06, federal_income = 0.14, state_income = 0.05, union_dues = 10;
int gross_pay, hours_worked, number_of_dependents, ss_withheld, federal_withheld, state_withheld, net_pay, insurance, overtime_pay, again;
cout << "This program will calculate payroll for an employee." << endl;
do
{
cout << "\n\nEnter the number of hours the employee worked: " << endl;
cin >> hours_worked;
if (hours_worked > 40) {
overtime_pay = (hours_worked - 40) * overtime_rate;
gross_pay = (40 * hourly_wage) + overtime_pay;
}
else {
gross_pay = hours_worked * hourly_wage;
}
cout << "\n\nEnter the number of dependents for employee: " << endl;
cin >> number_of_dependents;
if (number_of_dependents >= 3) {
insurance = 35;
}
else {
insurance = 0;
}
// Payroll Calculation
ss_withheld = gross_pay * social_security;
federal_withheld = gross_pay * federal_income;
state_withheld = gross_pay * state_income;
net_pay = gross_pay - (ss_withheld + federal_withheld + state_withheld + insurance + union_dues);
cout << "\n\nGross Pay: $" << gross_pay << endl;
cout << "Social Security Withhholding: $" << ss_withheld << endl; // Not calculating. Shows $0
cout << "Federal Withholding: $" << federal_withheld << endl; // Not calculating. Shows $0
cout << "State Withholding: $" << state_withheld << endl; // Not calculating. Shows $0
cout << "Union Dues: $" << union_dues << endl;
cout << "Insurance Deduction: $" << insurance << endl;
cout << "Net Pay: $" << net_pay << endl;
cout << "\nDo you want to do another employee(Y/N)? ";
cin >> again;
} while (again == 'y' || again == 'Y');
cout << "\nHope they enjoy the money!" << endl;
return 0;
#包括
使用名称空间std;
int main()
//参数:无
//返回:零
//电话:无
{
国际施工时薪=16.78,加班费=25.17,社会保障=0.06,联邦收入=0.14,州收入=0.05,工会会费=10;
总工资、工作时间、受抚养人人数、代扣代缴党卫军、联邦代扣代缴、州代扣代缴、净工资、保险费、加班费等;
cout=3){
保险=35;
}
否则{
保险=0;
}
//工资计算
扣缴工资=工资总额*社会保障;
联邦预扣=工资总额*联邦收入;
国家扣留=工资总额*国家收入;
净工资=总工资-(代扣代缴党费+联邦代扣代缴+州代扣代缴+保险+工会会费);
cout看起来您正在为双值创建int常量
#include "stdafx.h";
#include <iostream>
using namespace std;
int main()
// Parameters: None
// Returns: Zero
// Calls: None
{
int const union_dues = 10;
double const hourly_wage = 16.78, overtime_rate = 25.17, social_security = 0.06, federal_income = 0.14, state_income = 0.05;
double gross_pay, hours_worked, number_of_dependents, ss_withheld, federal_withheld, state_withheld, net_pay, insurance, overtime_pay, again;
cout << "This program will calculate payroll for an employee." << endl;
do {
cout << "\n\nEnter the number of hours the employee worked: " << endl;
cin >> hours_worked;
if (hours_worked > 40) {
overtime_pay = (hours_worked - 40) * overtime_rate;
gross_pay = (40 * hourly_wage) + overtime_pay;
}
else {
gross_pay = hours_worked * hourly_wage;
}
cout << "\n\nEnter the number of dependents for employee: " << endl;
cin >> number_of_dependents;
if (number_of_dependents >= 3) {
insurance = 35;
}
else {
insurance = 0;
}
// Payroll Calculation
ss_withheld = gross_pay * social_security;
federal_withheld = gross_pay * federal_income;
state_withheld = gross_pay * state_income;
net_pay = gross_pay - (ss_withheld + federal_withheld + state_withheld + insurance + union_dues);
cout << "\n\nGross Pay: $" << gross_pay << endl;
cout << "Social Security Withhholding: $" << ss_withheld << endl; // Not calculating. Shows $0
cout << "Federal Withholding: $" << federal_withheld << endl; // Not calculating. Shows $0
cout << "State Withholding: $" << state_withheld << endl; // Not calculating. Shows $0
cout << "Union Dues: $" << union_dues << endl;
cout << "Insurance Deduction: $" << insurance << endl;
cout << "Net Pay: $" << net_pay << endl;
cout << "\nDo you want to do another employee(Y/N)? ";
cin >> again;
} while (again == 'y' || again == 'Y');
cout << "\nHope they enjoy the money!" << endl;
return 0;
}
#包括“stdafx.h”;
#包括
使用名称空间std;
int main()
//参数:无
//返回:零
//电话:无
{
int const union_dues=10;
双职工小时工资=16.78,加班费=25.17,社会保障=0.06,联邦收入=0.14,州收入=0.05;
双倍工资总额、工作时间、受抚养人人数、代扣代缴党卫军、联邦代扣代缴、州代扣代缴、净工资、保险费、加班费;
cout=3){
保险=35;
}
否则{
保险=0;
}
//工资计算
扣缴工资=工资总额*社会保障;
联邦预扣=工资总额*联邦收入;
国家扣留=工资总额*国家收入;
净工资=总工资-(代扣代缴党费+联邦代扣代缴+州代扣代缴+保险+工会会费);
不是所有的节目都是0吗?是的。“ss_扣留,联邦_扣留,州_扣留都在计算0美元。其他一切都在计算中。不确定出了什么问题,我会去运行它,看看哦,我看到你有两倍或浮点值初始化为Int,这就搞错了!新手搞错了。谢谢!