注册 登录
编程论坛 C++教室

C++程序闪退问题

小匠人 发布于 2021-03-22 10:15, 1579 次点击
#include<iostream>
#include<cmath>
using namespace std;

int main()
{
    cout << "Enter yearly interest rate,for exmple 7.25:";
        double annualInsterestRate;
        cin >> annualInsterestRate;
        double monthlyInsterestRate = annualInsterestRate/1200;
        cout << "Enter number of years as an integer,for example 5:";
        double number0fYears;
        cin >> number0fYears;
        cout << "Enter loan amount ,for exmple 120000.95:";
        double loanAmount;
        cin >> loanAmount;
        double monthlyPayment = loanAmount*monthlyInsterestRate / (1 - 1 / pow(1 + monthlyInsterestRate, number0fYears * 12));
        double totalPayment = monthlyPayment * number0fYears * 12;
        monthlyPayment = static_cast<int>(monthlyPayment * 100) / 100.0;
        totalPayment = static_cast<int>(totalPayment * 100) / 100.0;
        cout << "The monthly payment is " << monthlyPayment<< endl << "The total payment is " << totalPayment << endl;
        cin.get();
        return 0;
        
}



分别输入3
5
1000
没有显示输出结果,为什么会直接闪退呀,加了cin.get()也没用
3 回复
#2
lin51616782021-03-22 10:52
那就加两个
#3
小匠人2021-03-24 08:03
回复 2楼 lin5161678
牛批了老铁,确实加两个问题就解决了,直呼好家伙,谢谢老铁
#4
小匠人2021-03-24 08:50
回复 3楼 小匠人
在程序的末尾加一个system("pause");也可以防止闪退~
1