C++ 计算定期存款本利和:年利率3.15%
#include <iostream>
#include <cmath>
int main() {
double principal, interestRate, total;
int years;
// 输入存款本金和存款年限
std::cout << "请输入存款本金:";
std::cin >> principal;
std::cout << "请输入存款年限:";
std::cin >> years;
// 计算到期后的本利之和
interestRate = 3.15 / 100; // 年利率转化为小数
total = principal * pow(1 + interestRate, years);
// 输出到期后的本利之和
std::cout << "到期后的本利之和为:" << total << std::endl;
return 0;
}
输入示例:
请输入存款本金:1000.5
请输入存款年限:2
输出示例:
到期后的本利之和为:1064.52
原文地址: http://www.cveoy.top/t/topic/pku0 著作权归作者所有。请勿转载和采集!