Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/148.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
计算问题C++; 我对C++很陌生,这是家庭作业。我不明白发生了什么事。当我运行此程序时,如果我为当前工资输入60000,为加薪输入.05,那么一切正常。但是如果我为当前工资输入52000,为加薪输入.23,那么追溯工资将显示为5982.00,而不是5980.00。这和小数有关吗?我真的不知道。提前谢谢 // Variables char fullName[30]; // The user's full name - INPUT int currentAnnual; // The users's current annual salary - INPUT float percentIncrease; // The percent increase due on the // current annual salary - INPUT // The retroactive pay float retroactive; // The new monthly salary based on the pay increase and the new salary float monthlySalary; // The new salary the user should receive based on their old salary // and their pay increase float newSalary; for(int lcv = 1; lcv <= 3; lcv++) { // INPUT cout << "What is your full name? "; cin.getline(fullName, 30); cout << "What is your current salary? "; cin >> currentAnnual; cout << "What is your pay increase (please input percentage in" "decimal format)? "; cin >> percentIncrease; // PROCESSING newSalary = (currentAnnual * percentIncrease) + currentAnnual; monthlySalary = newSalary / 12; retroactive = (monthlySalary - (currentAnnual / 12)) * 6; // OUTPUT cout << endl; cout << fullName << "'s Salary Information\n"; cout << left << setw(15) << "New Salary" << setw(19) << "Monthly Salary" << "Retroactive Pay\n"; cout << setprecision(2); cout << fixed; cout << right << setw(10) << newSalary << setw(19) << monthlySalary << setw(20) << retroactive << endl << endl; cout << "<Press enter to continue>"; cin.ignore(100, '\n'); cin.ignore(1000, '\n'); cout << endl; } //变量 字符全名[30];//用户的全名-输入 int currentAnnual;//用户当前年薪-输入 浮动百分比增加;//到期应付的增加百分比 //当前年薪-输入 //追溯支付 浮动追溯; //基于加薪和新工资的新月薪 按月浮动; //用户应根据其旧薪资获得的新薪资 //以及他们的工资增长 浮动新闻汇编; 对于(int lcv=1;lcv百分比增加; //加工 newSalary=(当前年度*增长百分比)+当前年度; 每月平均=新闻日历/12; 追溯=(每月-(当前年度/12))*6; //输出 cout_C++ - Fatal编程技术网

计算问题C++; 我对C++很陌生,这是家庭作业。我不明白发生了什么事。当我运行此程序时,如果我为当前工资输入60000,为加薪输入.05,那么一切正常。但是如果我为当前工资输入52000,为加薪输入.23,那么追溯工资将显示为5982.00,而不是5980.00。这和小数有关吗?我真的不知道。提前谢谢 // Variables char fullName[30]; // The user's full name - INPUT int currentAnnual; // The users's current annual salary - INPUT float percentIncrease; // The percent increase due on the // current annual salary - INPUT // The retroactive pay float retroactive; // The new monthly salary based on the pay increase and the new salary float monthlySalary; // The new salary the user should receive based on their old salary // and their pay increase float newSalary; for(int lcv = 1; lcv <= 3; lcv++) { // INPUT cout << "What is your full name? "; cin.getline(fullName, 30); cout << "What is your current salary? "; cin >> currentAnnual; cout << "What is your pay increase (please input percentage in" "decimal format)? "; cin >> percentIncrease; // PROCESSING newSalary = (currentAnnual * percentIncrease) + currentAnnual; monthlySalary = newSalary / 12; retroactive = (monthlySalary - (currentAnnual / 12)) * 6; // OUTPUT cout << endl; cout << fullName << "'s Salary Information\n"; cout << left << setw(15) << "New Salary" << setw(19) << "Monthly Salary" << "Retroactive Pay\n"; cout << setprecision(2); cout << fixed; cout << right << setw(10) << newSalary << setw(19) << monthlySalary << setw(20) << retroactive << endl << endl; cout << "<Press enter to continue>"; cin.ignore(100, '\n'); cin.ignore(1000, '\n'); cout << endl; } //变量 字符全名[30];//用户的全名-输入 int currentAnnual;//用户当前年薪-输入 浮动百分比增加;//到期应付的增加百分比 //当前年薪-输入 //追溯支付 浮动追溯; //基于加薪和新工资的新月薪 按月浮动; //用户应根据其旧薪资获得的新薪资 //以及他们的工资增长 浮动新闻汇编; 对于(int lcv=1;lcv百分比增加; //加工 newSalary=(当前年度*增长百分比)+当前年度; 每月平均=新闻日历/12; 追溯=(每月-(当前年度/12))*6; //输出 cout

计算问题C++; 我对C++很陌生,这是家庭作业。我不明白发生了什么事。当我运行此程序时,如果我为当前工资输入60000,为加薪输入.05,那么一切正常。但是如果我为当前工资输入52000,为加薪输入.23,那么追溯工资将显示为5982.00,而不是5980.00。这和小数有关吗?我真的不知道。提前谢谢 // Variables char fullName[30]; // The user's full name - INPUT int currentAnnual; // The users's current annual salary - INPUT float percentIncrease; // The percent increase due on the // current annual salary - INPUT // The retroactive pay float retroactive; // The new monthly salary based on the pay increase and the new salary float monthlySalary; // The new salary the user should receive based on their old salary // and their pay increase float newSalary; for(int lcv = 1; lcv <= 3; lcv++) { // INPUT cout << "What is your full name? "; cin.getline(fullName, 30); cout << "What is your current salary? "; cin >> currentAnnual; cout << "What is your pay increase (please input percentage in" "decimal format)? "; cin >> percentIncrease; // PROCESSING newSalary = (currentAnnual * percentIncrease) + currentAnnual; monthlySalary = newSalary / 12; retroactive = (monthlySalary - (currentAnnual / 12)) * 6; // OUTPUT cout << endl; cout << fullName << "'s Salary Information\n"; cout << left << setw(15) << "New Salary" << setw(19) << "Monthly Salary" << "Retroactive Pay\n"; cout << setprecision(2); cout << fixed; cout << right << setw(10) << newSalary << setw(19) << monthlySalary << setw(20) << retroactive << endl << endl; cout << "<Press enter to continue>"; cin.ignore(100, '\n'); cin.ignore(1000, '\n'); cout << endl; } //变量 字符全名[30];//用户的全名-输入 int currentAnnual;//用户当前年薪-输入 浮动百分比增加;//到期应付的增加百分比 //当前年薪-输入 //追溯支付 浮动追溯; //基于加薪和新工资的新月薪 按月浮动; //用户应根据其旧薪资获得的新薪资 //以及他们的工资增长 浮动新闻汇编; 对于(int lcv=1;lcv百分比增加; //加工 newSalary=(当前年度*增长百分比)+当前年度; 每月平均=新闻日历/12; 追溯=(每月-(当前年度/12))*6; //输出 cout,c++,C++,你应该做monthlySalary=newSalary/12.0;而不是monthlySalary=newSalary/12; 所以您必须指定要在浮点数上除法。否则结果将是整数。例如125./12=10但是125./12.=10.41(6)。当然,您会得到错误的结果 尝试将.0或只是添加到所有常量中。您应该执行monthlySalary=newSalary/12.0;而不是monthlySalary=newSalary/12; 所以您必须指定要在浮点数上除法。否则结果将是整数。例如125./12

你应该做
monthlySalary=newSalary/12.0;
而不是
monthlySalary=newSalary/12;
所以您必须指定要在浮点数上除法。否则结果将是整数。例如
125./12=10
但是
125./12.=10.41(6)
。当然,您会得到错误的结果


尝试将
.0
或只是
添加到所有常量中。

您应该执行
monthlySalary=newSalary/12.0;
而不是
monthlySalary=newSalary/12;
所以您必须指定要在浮点数上除法。否则结果将是整数。例如
125./12=10
但是
125./12.=10.41(6)
。当然,您会得到错误的结果


尝试将
.0
或仅将
添加到所有常量中。

currentAnnual/12
更改为
currentAnnual/12.0
,以强制执行浮点计算。否则,该部分计算将四舍五入到下面最接近的整数。

currentAnnual/12
更改为de>Current/12.0强制进行浮点计算。否则,该部分计算将四舍五入到下面最接近的整数。

浮点计算不如预期的准确。请尝试在上述代码中将
浮点
替换为
双精度
双精度
是一个错误)“双精度浮点数”;它可以存储比
浮点数多得多的值,并且更精确)

此外,操作顺序有时很重要,因此您可能希望将
追溯计算重新排序为类似的顺序

6 * monthlySalery - currentAnnual / 0.5;

然后尝试其他组合,看看哪个组合效果最好。

浮点计算不如您预期的准确。请尝试在上述代码中将
浮点
替换为
双精度
双精度
是一个“双精度浮点数”)“它可以存储比浮点值多得多的值,而且更精确)

currentAnnual / 12
此外,操作顺序有时很重要,因此您可能希望将
追溯计算重新排序为类似的顺序

6 * monthlySalery - currentAnnual / 0.5;
并尝试其他组合,看看什么效果最好

currentAnnual / 12
C中两个整数的除法是一个“整数除法”(它给出一个整数),我想你不希望这样。一个解决方案是将它改为
currentAnnual/12.0
。无论如何,了解这里发生的事情很重要


C中两个整数的除法是“整数除法”(它给出一个整数),我想你不希望这样。一个解决方案是将它改为
currentAnnual/12.0
。无论如何,你必须了解这里发生的事情。

newSalary
已经是一个float。
float/int
产生一个float,而不是int。
newSalary
已经是一个float。
float/int
产生一个floaT,而不是一个具有所有疣和复杂性的C++。不幸的是,你必须把它当作第一语言来学习。布伦南:这是一个无用的误导性的评论……有一些问题,就像我在java里学过的一年课一样。ARS,这在技术上不是我的第一语言。但是对我班上的其他人来说,它是。所有的疣和复杂性都有C++,很不幸的是,你必须把它当作第一语言来学习。布伦南:这是一个无用的误导性的评论…有一些关门问题,它们是故意的论证性的……我花了一年的时间。女孩,那是在爪哇,但那是在高中,所以已经有几年了,所以从技术上讲,它不是我的第一语言。但对我班上的许多其他人来说,它是。我在哪里谈到了新闻日历?哦,那是为了添加到埃拉弗的答案中,而不是你的答案中。我很抱歉。现在……52000/12的年报是4333.33333……从数学上来说,但因为currentAnnual也是一个浮点值,所以它是小数部分的四舍五入。我在哪里谈过newSalary?哦,这是要添加到Elafer的答案中的,不是你的。我很抱歉。从数学上来说,现在的52000/12的年份应该是4333.33333,但因为currentAnnual也是一个浮点值,所以它是小数p的四舍五入艺术