d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Need Some Help > Fg Being Offered
Add Reply New Topic New Poll
Member
Posts: 8,606
Joined: Jun 6 2007
Gold: 3.00
Aug 14 2015 01:22pm
I need to add exception handling to this but unsure how i would go about this. I need to make sure the user is only allowed to input numerical values and not strings or negative numbers. Telling them "Sorry, that is not a valid numerical value. Please try again. Offering at least 500 FG for the help or more depending how clean you can input the error handling and explain what you did

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

int loanAmount; //amount of the loan
double loanInterest; // the loan interest rate
int loanYears; //years of the loan
int loanTerm = loanYears; //loan term in months
double loanPay; //variable for outputting the payment

int main()
{
cout<<"Enter Loan Amount";
cin>>loanAmount;
cout<<"Enter Loan Interest";
cin>>loanInterest;
cout<<"Enter Loan Years";
cin>>loanYears;
cout<<"Loan Term (months)";


loanPay = (loanAmount * loanInterest) / (1 - pow(1+loanInterest,-loanYears)); //Formula to figure mortgage payment amount

cout<< "Your Monthly Payment Amount is: $"<< loanPay; //prints out monthly payment amount
return 0;
}
Member
Posts: 2,757
Joined: Nov 26 2007
Gold: 1,214.81
Aug 14 2015 02:26pm
cout<<"Enter Loan Amount";
cin>>loanAmount;
while(!cin){
cout<<"Sorry, that is not a valid numerical value. Please try again.";
cin>>loanAmount;
}
Member
Posts: 8,606
Joined: Jun 6 2007
Gold: 3.00
Aug 14 2015 02:41pm
Edit: I got it working using another methos, thanks

This post was edited by Extrude on Aug 14 2015 03:07pm
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll