1.

Calculate the total interest on a number of different loans.

Answer»

However, there is no interest until the sum of 1000 is REACHED, but there is a 20% interest RATE for the remaining quantities in the array. In this scenario, we will write a function "totalInterest" that takes two arguments: the first is the number of amounts in the array, and the second is the array of amounts. For example, if the first input is 4, and the amounts are 1000, 2000, 3000 and 4000. The total interest would be = 20% of 1000 + 20% of 2000 + 20% of 3000 + 20% of 4000 = 2000.

The C++ code for the above-mentioned problem is as follows:

#include<bits/stdc++.h>using namespace std;double totalInterest(int totalAmounts, VECTOR<int> a){ double totalInterestValue = 0; for(int i = 0;i < totalAmounts;i ++) { if(arr[i] < 1000)continue; totalInterestValue = totalInterestValue + (1.0*(arr[i]-1000)*0.2); } return totalInterestValue;}int main(){ int totalAmounts; cin >> totalAmounts; vector<int> a(totalAmounts); for(int i = 0; i < totalAmounts; i ++)cin >> a[i]; cout << totalInterest(totalAmounts, a) << endl; return 0;}

In the code given above, we first declare a decimal variable "totalInterestValue" which would store the total interest YIELDED in our question. After that, we keep on INCREMENTING its value by adding the total interest generated for each amount given if the value of the amount is greater than or equal to 1000. The interest is calculated only for amounts greater than 1000 and at a rate of 20%.



Discussion

No Comment Found