Interest calculation

Asked

Viewed 594 times

3

[Engelbrecht et al., 2012] Develop a program that receives from the user, the value of an application and the value of the initial interest rate. Whereas this interest rate increases 0.025% per month, so store in vectors, with 12 elements each:

  1. The value of interest rates in each month
  2. The value of interest in each month
  3. And the application value corrected each month

After that, show the initial value of the application and the contents of vectors.

How do I do this program? I’m not able to do for the rate of interest will increase.

*Ex: Month 1 = 0.025%, Month 2 = 0.050%, Month 3 = 0.075%.

#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;


int vetor[12];
float apini;
float txjini;
int num;


 int main(int argc, char** argv) {

   cout<<"Informe o valor da aplicacao inicial: "<<endl;
   cin>>apini;
   cout<<"Informe o valor da taxa de juros inicial: "<<endl;
   cin>>txjini;

  for(int i = 0; i<=12; i++)
  {
    txjini = (vetor[i]*0,025);
    cout<<"O valor das taxas de juros em cada mes e de:  "<<txjini<<endl;   
  }

return 0;
 }
  • Has anyone answered your question? If yes, mark as answered

2 answers

3


If the interest rate has to vary with each installment then you have to use a variable that increments the installment to calculate the new interest, nothing changes without a variation, the calculation was being done without it. I was still not considering the value applied and the initial interest rate.

I just asked the question. I improved the readability of the code. I didn’t use the array because it is not necessary to resolve the question. And when you create it, it is much more complicated than what you were doing, you will need to create a struct or class for each plot.

Apart from the stream this code is C and not C++.

Do not use binary floating point in monetary values.

#include <iostream>
using namespace std;

int main() {
    cout << "Informe o valor da aplicacao inicial: " << endl;
    float ValorInicial;
    cin >> ValorInicial;
    cout << "Informe o valor da taxa de juros inicial: " << endl;
    float JurosInicial;
    cin >> JurosInicial;
    JurosInicial /= 100;
    for (int i = 0; i < 12; i++) {
        cout << "O valor das taxas de juros em cada mes e de:  " << ValorInicial * (JurosInicial + 0.025 * i) << endl;
    }
}

Behold working in the ideone. And in the repl it.. Also put on the Github for future reference.

  • Friend, thank you! You helped so much here.....

0

You would have to store the interest rate of each month in one vector 12-seater.

Ex.:

float txj[12];

And then on for() you do so:

for(int i = 0; i <= 12; i++)
{
    txj[i] = (i + 1) * txjini;

    cout << "Juros do mes " << i << ": " << txj[i] << endl;
}

Something like that. :)

  • It helped too much :D! Killed my doubt...

  • Good, @Kennedymedeiros! We need it. : D

Browser other questions tagged

You are not signed in. Login or sign up in order to post.