C 贷款计算器
C++ Loan Calculator
本文关键字:计算器 更新时间:2023-10-16
我正在尝试编写C 的程序,该程序获得了首发贷款余额,年利率和每月付款,并打印了一个时间表,该时间表显示余额在每次之后的余额截止贷款的月份,或者直到60个月过去了。
//Calculates a loan payment schedule
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
double startingBalance = 0.0;
double interestRate = 0.0;
double monthlyPayment = 0.0;
double monthlyBalance = 0.0;
double compountInterest = 0.0;
double balance = 0.0;
int month = 0;
cout << fixed << showpoint;
cout << setprecision(2);
cout << "Starting loan balance: " ;
cin >> startingBalance; //User input starting loan balance
if (startingBalance <= 0){
cout <<"nPlease enter a positive number: " ;
cin >> startingBalance;
}
cout << "nAnnual interest rate: " ;
cin >> interestRate; //User input interest rate
if ((interestRate <= 0) || (interestRate > 1)){
cout <<"nPlease enter an interest rate ranging from 0 to 1: " ;
cin >> interestRate;
}
cout << "nMonthly payment: " ;
cin >> monthlyPayment; //User input monthly payment
if (monthlyPayment <= 0){
cout <<"nPlease enter a positive number: " ;
cin >> interestRate;
}
startingBalance = balance;
cout << "nMonth t Balancen" << endl; //Outputs a schedule of payments
while ((balance > 0) || (month < 61))
{
balance += (startingBalance * (interestRate/12));
balance -= monthlyPayment;
month = month++;
cout << month << "t" << balance << "n";
}
return 0;
}
我相信陈述正确,但结果我一直在得到这些陈述
Starting loan balance: 10000.00
Annual interest rate: 0.0525
Monthly payment: 500.00
Month Balance
1 -500.000
2 -1000.00
3 -1500.00
等,直到61个月过去了。
startingBalance = balance;
看起来应该逆转的
while ((balance > 0) || (month < 61))
您的描述表明&amp; amp;将更合适
相关文章:
- 使用 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计算器使用头文件进行计算操作和堆栈;用于堆栈的矢量
- 如何在我的基本计算器中循环遍历数组
- 如果 GPA 计算器的语句问题
- 我的C++计算器似乎出了什么问题?