各种利率计算器
Varied interest rate 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.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;
我想那是你想要的。
相关文章:
- 使用 BMI 计算器对C++中的数字进行四舍五入的问题
- 我在c ++矩阵计算器程序中找不到错误
- C++计算器,不能单独除以 0
- 如何正确解析子字符串,以便它们对我的新手计算器有效?
- Arduino 基础 2 计算器无法C++工作
- 需要有关我的平均计算器代码的建议
- C++ - 在我尝试制作一个简单的计算器时有一个"uninitialized local variable y used"警告
- 野牛/flex:计算器将双精度值解释为整数,所以我添加了 YYSTYPE 双精度 #define 但我有多个编译错误
- C++计算器运算符
- 使用WIN32 API的击球平均计算器
- RPN计算器c++错误处理和多个运算符
- C++查找用于构建单行计算器
- 如何修复这个基本计算器
- 用于加法和减法的十六进制计算器
- 桌面计算器出现问题.C++程序设计语言
- 如何对堆栈中的所有项目求和?Postfix计算器
- RPN计算器使用头文件进行计算操作和堆栈;用于堆栈的矢量
- 如何在我的基本计算器中循环遍历数组
- 各种利率计算器
- 利率计算器 C++.