gpt4 book ai didi

c++ - 为什么这些简单的函数会给出天文数字大或小的数字?

转载 作者:行者123 更新时间:2023-11-28 06:26:48 25 4
gpt4 key购买 nike

所以我的教授要求我们制作一个程序,根据输入的工资率和工作时间计算预算。百分比是教授给出的。另外,我是 C++ 的新手,所以请原谅我。

#include <iostream>

using namespace std;

int main()

{
int hours;
double Pay;

const double Net = hours * Pay;
const double Tax = Net * .14;
const double afterTax = Net - Tax;
const double Clothes = .1 * afterTax;
const double Supplies = .01 * afterTax;
const double Bonds = .25 * afterTax;
const double Parents = Bonds / 2;

cout << "Please enter hours worked \n";
cin >> hours;
cout << "Please enter hourly rate \n";
cin >> Pay;

cout << "Total Number of hours worked: " << hours << endl;
cout << "Total income before taxes: " << Net << endl;
cout << "Net Income: " << afterTax << endl;
cout << "Money Spent on clothes and accessories: " << Clothes << endl;
cout << "Money spent on school supplies: " << Supplies << endl;
cout << "Money spent on savings bonds: " << Bonds << endl;
cout << "Money spent by parents for savings bonds: " << Parents << endl;
cout << "Remaining: " << afterTax - Clothes - Supplies - Bonds << endl;

return 0;
}

最佳答案

hours 和其他几个变量未初始化,但您使用它们的值来初始化其他变量。您需要重新安排计算,以便在用户输入必要的项目后执行这些计算。

关于c++ - 为什么这些简单的函数会给出天文数字大或小的数字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28386794/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com