We need a program to calculate future cost of a loan taken by a user. The financial institution charges the following interest rates for loans. The user inputs are the amount of loan desired, the loan period (number of years), and the number of compounding per year. Your program should determine the interest rate based on the amount of the loan. Your program should calculate the future dollar amount of this loan. The total amount of interest at the end of the loan period. Your program should incorporate a looping structure so that the user could check out many loan scenarios. You need to determine how to stop the loop. Interest rate schedule is per following schedule: Loan < 10k rate = 2% 10k =

Respuesta :

Answer:

Follows are the code to this question:

#include<iostream>//defining the header file

#include<cmath>//defining the header file

using namespace std;

int main() //defining main method

{

   double p,a,r;//defining double variable  

   int n,t;//defining integer variable

   bool flag = true;//defining bool variable flag  

   while(flag) //defining while loop for input value

   {

       cout<<"Enter Present Worth: ";//print message

       cin>>p;//input value in p

       cout<<"Enter number of compounding: ";//print message

       cin>>n;//input value in n

       cout<<"Enter Loan Period: ";//print message

       cin>>t;//input value in t

       if (p<10000)//defining if block that check principle value is graeter then 10000

       {

           r = 0.02;//defining r varaible that store 0.02 value  

       }

       else if (p>=10000 && p<=50000)//defining else if that value of p is in 10000 to 50000  

       {

           r = 0.05;//defining r varaible that store 0.05 value

       }

       else if (p>50000)//defining else if that value of p is in 50000

       {

           r = 0.07;//defining r varaible that store 0.07 value

       }

       a = p*pow((1 + r/((double)n)), n*t);//defining formula for calculate A  

       cout<<"\nInterest Rate of Loan: "<<r<<endl;//print r rate value

       cout<<"Future Worth: $"<<a<<endl;//print A value

       cout<<"Total Interest: $"<<(a-p)<<endl<<endl;//print total interest value

       char c;//defining char variable c

       cout<<"Do you want to check for more loans(Press 'Y' for yes, otherwise press any other key): ";//print message

       cin>>c;//input char value

       if (c!= 'Y' && c!= 'y')//define if block that check c value is not equal to y

           flag = false;//use flag that hold  value false

   }

   cout<<"Thank you!!!"<<endl;//print message

   return 0;

}

Output:

please find the attched file.

Explanation:

In the code, inside the main method three double variables "p, a, and, r", two integer variable "n and t", a bool variable is defined, in which double variable "p, n, and t" is used to input the value from the user-end.

  • In the next step, a condition statement has used that check the p-value and set the value according to the "p" variable value.
  • The formula is used that calculates the value and prints its value, and uses a char variable that takes input "y" for again run the code or input other value to exit the program.  
Ver imagen codiepienagoya