各种利率计算器

Varied interest rate calculator

本文关键字:计算器 利率      更新时间:2023-10-16

嘿,我是编码的新手,想知道你们是否可以帮助我计算不同的利率,然后将它们添加到下一个利率中。因此,基本上我正在尝试获得利率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.252年级增加1.27,总计102.523年级增加1.28,总计103.804年级增加1.30,总计105.095年级增加1.31,总计106.416年级增加1.33,总计107.747年级增加1.35,总计109.098年级增加1.36,总计110.459年级增加1.38,总计111.8310年级增加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;
}

您需要使用功能替换

cout << " Year " << index << " adds 1.25% for a total of " << .0125 * intv + intv << "." << endl; 

该功能可以将索引转换为添加值,例如

double foo(int index);

输入值为"索引",输出值是添加值,例如1.25%,1.38%.etc。

然后删除所有cout行。只需添加此行:

cout << " Year " << index << " adds " << foo(index) * 100.0 << "% for a total of " << foo(index) * intv + intv << "." << endl; 

我想那是你想要的。