gpt4 book ai didi

c++ - 可变利率计算器

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

嘿,我是编码新手,想知道你们是否可以帮助我计算不同的利率,然后将它们添加到下一个利率中。所以基本上我试图获得利率 A 并将其添加到 100 的起始值。然后我想获得 100 的利率 B 并将该值添加到利息 A。到目前为止这是我的代码,但我得到 10 行对于每个利率。抱歉,如果这听起来令人困惑,但希望代码能让它更清楚,或者如果阅读本文的人愿意,我可以尝试更好地解释。谢谢!!

int intv;

cout << " Accumulate interest on a savings account. ";
cout << " Starting value is $100 and interest rate is 1.25% ";

cout << endl;

intv = 100;
index = 1;

while ( index <= 10 )

{
cout << " Year " << index << " adds 1.25% for a total of " << .0125 * intv + intv << "." << endl;
cout << " Year " << index << " adds 1.27% for a total of " << .0127 * intv + intv << "." << endl;
cout << " Year " << index << " adds 1.28% for a total of " << .0128 * intv + intv << "." << endl;
cout << " Year " << index << " adds 1.30% for a total of " << .0130 * intv + intv << "." << endl;
cout << " Year " << index << " adds 1.31% for a total of " << .0131 * intv + intv << "." << endl;
cout << " Year " << index << " adds 1.32% for a total of " << .0132 * intv + intv << "." << endl;
cout << " Year " << index << " adds 1.35% for a total of " << .0135 * intv + intv << "." << endl;
cout << " Year " << index << " adds 1.36% for a total of " << .0136 * intv + intv << "." << endl;
cout << " Year " << index << " adds 1.38% for a total of " << .0138 * intv + intv << "." << endl;
cout << " Year " << index << " adds 1.40% for a total of " << .0140 * intv + intv << "." << endl;

index = index + 1;

}

我不想为我做这件事,我只是想要提示。我想自己解决这个问题,但我不知道该怎么做。

期望的结果是程序给我这个:

第 1 年增加 1.25,总计 101.25第 2 年加 1.27 总计 102.52第 3 年加 1.28 总计 103.80第 4 年加 1.30 总计 105.09第 5 年加 1.31 总计 106.41第 6 年加 1.33 总计 107.74第 7 年加 1.35 总计 109.09第 8 年加 1.36 总计 110.45第 9 年加 1.38 总计 111.83第 10 年增加 1.40,总计 113.23

贷记的总利息为 13.23

最佳答案

听起来你可以使用 for 循环:

double rate = 0.125;

for (unsigned int index = 0; index < max_rates; ++index)
{
cout << " Year " << index << " adds "
<< (rate * 100.0)
<< "% for a total of "
<< rate * intv + intv << "." << endl;
rate += 0.002;
}

关于c++ - 可变利率计算器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21539951/

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