Interest calculation

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. Considering that this interest rate increases by 0.025% per month, then store in vectors with 12 elements each:

     
  • The value of interest rates each month
  •   
  • The amount of interest in each month
  •   
  • And the application value corrected each month
  •   

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

         

    How do I do this program? I can not do it for the   interest rates 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;
     }
    
        
    asked by anonymous 30.11.2017 / 22:04

    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 amount applied and the initial interest rate.

    I just doubted the question. I improved the readability of the code. I did not use the array because it is not necessary to solve the question. And when you create it, it's a lot more complicated than you were doing, you'll need to create a struct or class for each plot.

    stream this code is C and not C ++.

    Do not use floating point binary 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;
        }
    }
    

    See running on ideone . And no Coding Ground . Also I put GitHub for future reference .

        
    30.11.2017 / 22:22
    0

    You would have to store the interest rate for each month in a vector with 12 positions.

    Ex:

    float txj[12];
    

    And then in for() you do so:

    for(int i = 0; i <= 12; i++)
    {
        txj[i] = (i + 1) * txjini;
    
        cout << "Juros do mes " << i << ": " << txj[i] << endl;
    }
    
    More or less. :)

        
    30.11.2017 / 22:14