Solved C++ close problem

May 13, 2011 at 13:36:31
Specs: Windows Vista
I've made a script to work out loan interest and such, but when I enter the details, it just closes, can someone read this and say what's wrong, please?

#include <iostream>
#include <cmath>
using namespace std;

int main() {
double Principal; // Original principal
double IntRate; // Interest rate, such as 0.075
double PayPerYear; // Number of payments per year
double NumYears; // Number of years in loan
double Payment; // The regular payment
double numer, denom; // Temporary work variables
double b, e; // Base and Exponent for call and pow( )

cout << "Enter loan amount: ";
cin >> Principal;

cout << "Enter interest rate: ";
cin >> IntRate;

cout << "Enter amount of payments per year: ";
cin >> PayPerYear;

cout << "Enter number of years in the loan: ";
cin >> NumYears;

numer = IntRate * Principal / PayPerYear;

e = - (PayPerYear * NumYears);
b = (IntRate / PayPerYear) + 1;

denom = 1 - pow(b, e);

Payment = numer / denom;

cout << "Payment is: " << Payment;

return 0;

}

I really wanna know why it just closes :(


See More: C++ close problem

Report •


#1
May 13, 2011 at 13:41:05
✔ Best Answer
Because you made a console program in Windows, and Windows closes console windows when the program stops using them.

The easiest fix would be to add

system("PAUSE");
just before the main() returns.

How To Ask Questions The Smart Way


Report •

#2
May 13, 2011 at 13:42:06
Go to a command prompt and run your application from there. You should then see the results.

Stuart


Report •

Related Solutions


Ask Question