Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

how do you modify the calcMortgage application to handle exceptions such as indi

ID: 3773230 • Letter: H

Question

how do you modify the calcMortgage application to handle exceptions such as indication of a letter as apposed to numbers being input.


#include <iostream>
#include <math.h>
using namespace std;

int main(){
int n;
double i,i_m,P,M;
cout<<"Enter Principal:";
cin>>P;
cout<<"Enter rate of interest:";
cin>>i;
i_m = i/1200;
cout<<"Number of months:";
cin>>n;
M = P * (i_m * pow((i_m+1),n) / (pow((i_m+1),n)-1));
cout<<"Monthly mortage is "<<M;
return 0;
}

Explanation / Answer

try

    {

int n;
double i,i_m,P,M;
cout<<"Enter Principal:";
cin>>P;
cout<<"Enter rate of interest:";
cin>>i;
i_m = i/1200;
cout<<"Number of months:";
cin>>n;
M = P * (i_m * pow((i_m+1),n) / (pow((i_m+1),n)-1));
cout<<"Monthly mortage is "<<M;

        throw -1;

    }

    catch (DOUBLE X)

    {

        // eXCEPTION CAUGHT

        cerr << "We caught an exception of type int" << endl;

    }