标题:C++程序闪退问题
只看楼主
小匠人
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2020-5-5
结帖率:50%
已结贴  问题点数:8 回复次数:3 
C++程序闪退问题
#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()也没用
搜索更多相关主题的帖子: cin cout double C++ for 
2021-03-22 10:15
lin5161678
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:45
帖 子:1136
专家分:3729
注 册:2011-12-3
得分:8 
那就加两个

https://zh.
2021-03-22 10:52
小匠人
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2020-5-5
得分:0 
回复 2楼 lin5161678
牛批了老铁,确实加两个问题就解决了,直呼好家伙,谢谢老铁
2021-03-24 08:03
小匠人
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2020-5-5
得分:0 
回复 3楼 小匠人
在程序的末尾加一个system("pause");也可以防止闪退~
2021-03-24 08:50



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-505209-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.076149 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved