Click here to Skip to main content
15,886,664 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
There are two banks – Bank A and Bank B. Their interest rates vary. You have received offers from both banks in terms of the annual rate of interest, tenure, and variations of the rate of interest over the entire tenure.You have to choose the offer which costs you least interest and reject the other. Do the computation and make a wise choice.

The loan repayment happens at a monthly frequency and Equated Monthly Installment (EMI) is calculated using the formula given below :

EMI = loanAmount * monthlyInterestRate / ( 11 / (1 + monthlyInterestRate)^(numberOfYears * 12))

 

Constraints:

1 <= P <= 1000000
1 <=T <= 50
1<= N1 <= 30
1<= N2 <= 30
 

Input Format:

First line: P principal (Loan Amount)
Second line: T Total Tenure (in years).
Third Line: N1 is the number of slabs of interest rates for a given period by Bank A. First slab starts from the first year and the second slab starts from the end of the first slab and so on.
Next N1 line will contain the interest rate and their period.
After N1 lines we will receive N2 viz. the number of slabs offered by the second bank.
Next N2 lines are the number of slabs of interest rates for a given period by Bank B. The first slab starts from the first year and the second slab starts from the end of the first slab and so on.
The period and rate will be delimited by single white space.
 

Output Format: Your decision either Bank A or Bank B.


What I have tried:

please help me with this,
The loan repayment happens at a monthly frequency and Equated Monthly Installment (EMI) is calculated using the formula given below :
EMI = loanAmount * monthlyInterestRate / ( 1 – 1 / (1 + monthlyInterestRate)^(numberOfYears * 12))
Posted
Updated 13-Aug-20 21:21pm
Comments
Sandeep Mewara 14-Aug-20 1:36am    
And what have you tried so far and where are you stuck?

Quote:
please help me with this,

This requirement comes from a challenge site, it is a challenge to you by you, it looks like you failed.
You show no attempt to solve the problem yourself, you have no question, your main effort is pasting the requirement, you just want us to do your HomeWork.
You did not even stated the king of help you want.

We do not do your HomeWork.
HomeWork is not set to test your skills at begging other people to do your work, it is set to make you think and to help your teacher to check your understanding of the courses you have taken and also the problems you have at applying them.
Any failure of you will help your teacher spot your weaknesses and set remedial actions.
Any failure of you will help you to learn what works and what don't, it is called 'trial and error' learning.
So, give it a try, reread your lessons and start working. If you are stuck on a specific problem, show your code and explain this exact problem, we might help.
 
Share this answer
 
I am not going to write any code for you. You need to do that. I will give you one tip though. It has to do with this part :
(1 + monthlyInterestRate)^(numberOfYears * 12)
You can use the pow function for this. It would look like this :
pow( 1 + monthlyInterestRate, numberOfYears * 12 );
for the expression above and only that part. You can add the rest of it since it is basic arithmetic.

It seems to me you need to start by reading the parameters from the input file. Then calculate payments for each month and do the accounting. I recommend writing things out a 'ledger' style where you have a serious of transactions listing starting balance, payment applied, interest added, and resulting balance for each month so you can check your work. The accounting means given a starting balance, an interest rate, and a payment, calculate the balance for the next month including added interest. First get that mathematics figured out and then write the logic to implement it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900