Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions ch02/ex2_2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//AUTHOR YASH PARSANA
//DATE 11-05-2021
//CALCULATOR To calculate a mortgage payment

#include<iostream>
using std::cin;
using std::cout;
using std::endl;

float po(float r,int n)
{
float ans=1;

for(int z=1;z<=n;z++)
{
ans*=r;
}
return ans;
}
int main()
{
float p_amount,rate; // FLOAT TAKES HALF SPACE AS COMPARE TO DOUBLE AND HERE HAVE NO REQUIREMENT OF DOUBLE
int year;

cout<<"Please Enter principal Amount : ";
cin>>p_amount;
cout<<endl<<"Please Enter rate of interest : ";
cin>>rate;
cout<<endl<<"Please Enter duration (in year) : ";
cin>>year;
cout<<endl;

int n=year*12;

rate=rate/1200;

float temp=po(1+rate,n);

float payment=(p_amount*rate*temp)/(temp-1);

cout<<"Your monthly payment is : "<<payment<<endl;




return 0;
}