作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
希望有人能提供帮助。我可以毫无错误地编译,我没有发现任何语法错误,但是当我运行它时,它崩溃了。在启动时调试段错误。全面披露,这是作业。我不是要找人来编写这个代码,只是看看我的问题和我现有的代码,也许会指出我所做的严重破坏了这个代码?
问题:您找到了一份为期五周的令人兴奋的暑期工作。例如,每小时支付 15.50 美元。假设你为暑期工作收入支付的总税额为 14%。缴纳税款后,您将净收入的 10% 用于购买下一学年的新衣服和其他配饰,另外 1% 用于购买学习用品。买了衣服和学习用品后,你用剩下的钱的 25% 购买储蓄国债。你每花 1 美元购买储蓄债券,你的 parent 就会花费 0.50 美元为你购买额外的储蓄债券。编写一个程序,提示用户输入一小时的工资率和每周工作的小时数。然后程序输出如下: A。您暑期工作的税前和税后收入。 b.你花在衣服和其他配饰上的钱。 C。你花在学习用品上的钱。 d.您用来购买储蓄债券的钱。 e.您 parent 为您购买额外储蓄债券所花的钱。
代码:
// Libraries defined
#include <iomanip>
#include <iostream>
using namespace std;
//Main function
int main ()
{
//Input variables
double hourlyrate;
double hweek1;
double hweek2;
double hweek3;
double hweek4;
double hweek5;
//Output variables
double beforetax;
double netincome;
double clothmoney;
double suppliesmoney;
double moneyonbonds;
double additionalbonds;
double remain;
//This statement takes care of the decimal places
cout << fixed << showpoint << setprecision(2);
//Input from user
cout << "Enter your hourly rate: " << hourlyrate;
cin >> hourlyrate;
cout << "Week 1: " << hweek1;
cin >> hweek1;
cout << "Week 2: " << hweek2;
cin >> hweek2;
cout << "Week 3: " << hweek3;
cin >> hweek3;
cout << "Week 4: " << hweek4;
cin >> hweek4;
cout << "Week 5: " << hweek5;
cin >> hweek5;
//Mathematics
beforetax = hourlyrate * (hweek1 + hweek2 + hweek3 + hweek4+
hweek5) ;
netincome = beforetax - beforetax * 0.14;
clothmoney = netincome * 0.1;
suppliesmoney = netincome * 0.01;
remain = netincome - clothmoney - suppliesmoney;
moneyonbonds = remain * 0.25;
additionalbonds = static_cast<double>(moneyonbonds) * .50;
//Output to user
cout << endl << "Income before tax = $" << beforetax << endl
<< "Net income = $" << netincome << endl << "Money for clothes/accesories = $"
<< clothmoney << endl << "Money for supplies = $"<< suppliesmoney << endl
<< "Money for saving bonds = $" << moneyonbonds << endl
<< "Additional saving bonds money = $" << additionalbonds;
return 0;
}
最佳答案
我收到这个错误
cout << "Enter your hourly rate: " << hourlyrate;
您尝试在初始化之前输出变量。这可能是无意的。
下一行是
cin >> hourlyrate
每个变量都是一样的。你应该初始化它们或者不输出它们。
关于C++ Segfault No 编译错误找不到原因,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18884518/
我是一名优秀的程序员,十分优秀!