c++ - 可变利率计算器

标签 c++ calculator

嘿,我是编码新手,想知道你们是否可以帮助我计算不同的利率,然后将它们添加到下一个利率中。所以基本上我试图获得利率 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/

相关文章:

javascript - 根据输入类型日期 html 在 javascript 中计算 2 个日期之间的时间

javascript - 我的 javascript 代码的语法错误

iphone - 如何将操作符符号 '+,-,/,*,mod' 等添加到制作计算器的标签中?

c++ - std::ios_base::sync_with_stdio 如何影响流缓冲?

c++ - STL映射和纯虚基类

php - 来自 Javascript 的谷歌计算器

javascript - JS加载响应不起作用

android - 如何从 DJI Professional 3 相机流式传输实时视频?

c++ - 将对象移动到 vector c++ 的前面

c++ - 非标准语法;使用 '&' 创建指向成员的指针 将成员函数分配给 vector 时出错