Exception Help Please

I have my exception screwed up somehow. I am very new to this and can really use a little help. I just need the one exception to work using the "try" statement. Here is my code any help would be greatly appreciated.

#include <iostream>
#include <cmath>

using std::cout;
using std::cin;
using std::endl;
using std::pow;

class Mortgage
{
private:
double loan, rate;
short years;
public:
Mortgage() = default;
void setLoan(double l) { loan = l; }
void setRate(double r) { rate = r; }
void setYears(short y) { years = y; }
double getMonthlyDue(double term) { return ((loan * (rate / 12) * term) / (term - 1)); }
double getTotalDue(double term) { return (getMonthlyDue(term) * years); }
};

int main()

{
Mortgage mort1;

double term, loan, rate;
int years;

cout << "Mortgage Amount: ";
cin >> loan;

try {
if(loan <= 0)
throw;
}
catch(int e)
{
cout << "An exception occurred" << e << '\n';
}

mort1.setLoan(loan);

cout << "Mortgage Interest Rate: ";
while (!(cin >> rate) || rate < 0)
cout << "Interest rate cannot be negative. Enter the amount: ";

mort1.setRate(rate);


cout << "How Many years will the loan be?: ";
while (!(cin >> years) || years < 0)
cout << "Loan period cannot be negative. Enter the amount: ";

mort1.setYears(years);
term = pow((1 + (rate / 12)), (12 * years));

int choice = 0;

while (choice != 3)
{
cout << endl;
cout << "1. Monthly Payment" << endl <<
"2. Total Payment" << endl <<
"3. Exit" << endl << endl <<
"Enter an option above: ";
cin >> choice;

if (choice == 1)
cout << "Monthly payment is " << mort1.getMonthlyDue(term) << "." << endl;
else if (choice == 2)
cout << "Total payment due is " << mort1.getTotalDue(term) << "." << endl;
}
}
Topic archived. No new replies allowed.