Question: In C++ modify this code to validate the input (not allow any negative numbers), and further format the output the user sees (make it fancy!!)
In C++ modify this code to validate the input (not allow any negative numbers), and further format the output the user sees (make it fancy!!)

Copied code:
#include
class Loan { public : Loan(); //default constructor void setLoanAmount (double); void setInterestRate(double); void setNumberofYears(double); double getMonthlyPayment(); double getTotalAmount(); private: double loanAmount, interestRate, numberOfYears; }; Loan::Loan () { setLoanAmount(0); setInterestRate(0); setNumberofYears (0); }// end default constructor
void Loan::setLoanAmount (double myLoanAmount) { loanAmount = myLoanAmount; }// end function set LoanAmount void Loan::setInterestRate(double myInterestRate) { interestRate = myInterestRate/100; }// end function set Interest Rate void Loan::setNumberofYears(double myNumberOfYears) { numberOfYears = myNumberOfYears; }// end function set Number of Years double Loan::getMonthlyPayment() { double term = pow(( 1 + ( interestRate / 12)), (12 * numberOfYears)); double payment = (loanAmount * (interestRate / 12) * term) / (term - 1); return payment; } // end function getMonthlyPayment double Loan::getTotalAmount() { return ( 12 * numberOfYears * getMonthlyPayment() ); }// end function get Total Amount
int main() { // declare a variable/object of type Loan Loan myLoan; // declare other variables of the program char choice; double loan, rate, year; do { // prompt and read the input from the user cout > loan; cout > rate; cout > year; // modify the values of the object myLoan.setLoanAmount(loan); myLoan.setInterestRate(rate); myLoan.setNumberofYears(year); // print the result to the user cout > choice; } while ( tolower( choice ) != 'n' ); // end do-while return 0; };
#include #include
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
