Investment program with tabulation table and one or two dimensional arrays

1

It is a school exercise on the use of c ++ fixes, although I can not understand how to make the exercise show tabulation of the month and the accumulated total and the total accumulated profit at the end of the term.

-----------------------------------------------------
% mensual| *monto ingresado por usuario (ej. %2.0)  |
-----------------------------------------------------
|   mes  |  cantidad  |   total acumulado           |
-----------------------------------------------------
  enero  | 1000       |   1000
 febrero |            |   1020                
                          1040

.... and so on consecutively until December

The problem is:

  

A person wants to invest a certain amount of money (for example $ 1000.00) in the bank, which gives a certain percentage of monthly interest (for example 2.0%).

     

The person wants to know what the amount of money will be after a year if all the money is reinvested. (Tip: consider each month as a counter that increases by 1 each time the cycle is repeated).

     

At the end you should print on the screen the total balance with the interest percentage (in this case 2%) of each month and your profit obtained at the end of the term (in this example 1 year = 12 months).

The code to enter variables as amount of investment, term, monthly interest of execution is:

#include<iostream>
using namespace std;
#define SIN_TIPO string         
int main() {
float capital;
float ganancia;
float porcentaje;
int plazo;


cout << " ingrese el capital" << endl;
cin >> capital;
cout << "ingrese porcentajem ensual" << endl;
cin >> porcentaje;
cout << "ingrese plazo" << endl;
cin >> plazo;
ganancia = capital*porcentaje;

cout << "La ganancia es:" << ganancia << endl;
return 0;
}

Any advice?

    
asked by Acidous 30.08.2018 в 06:38
source

2 answers

1

The first thing is that the board is wrong. If the interests are added to the capital, which is what is meant by reinvest . What you get is compound interest and it does not work by adding a fixed amount (according to your example) of 20 per month.

         Capital  Intereses        Total
Enero     1000,0       20,0       1020
Febrero   1020,0       20,4       1040,4   <<---  0,4 respecto a tu ejemplo
Marzo     1040,4       20,8       1061,2   <<---  1,2 respecto a tu ejemplo

The fact is that to get these results you do not need arrays or data structures, but only a loop, which should perform 12 iterations (one for each month of the year).

To tabulate the data you have at your disposal the library iomanip . An example:

int main()
{
  // setw establece el numero de caracteres del siguiente campo
  // el valor de setw hay que establecerlo en cada uso
  std::cout << std::setw(10) << "Mes"
            << std::setw(10) << "Capital"
            << std::setw(10) << "Intereses"
            << std::setw(10) << "Total"
            << '\n'
            << std::setprecision(2) // numeros con dos decimales
            << std::fixed;          // para que no salga notacion cientifica
                                    // a diferencia de setw, estos valores no se pierden

  float capital = 1000;
  float const interes = 0.02;

  for( int i=0; i<12; i++ )
  {
    float intereses = capital * interes;
    float total = capital + intereses;

    std::cout << std::setw(10) << i
              << std::setw(10) << capital
              << std::setw(10) << intereses
              << std::setw(10) << total
              << '\n';

    capital = total;
  }
}

To name the month, it's your turn to do it to you, I'm not going to give you all the exercise done.

    
answered by 30.08.2018 в 08:03
0

Welcome to StackOverflow.

It seems that what they ask you is to make an arrangement of the months and use a cycle for to show them. Example.

// Vector de meses
vector<string> meses {"Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"};

for(int i = 0; i < meses.size(); i++) {
    cout << meses[i] << endl;
}

In this case I used a vector and not an arrangement for simplicity, but for your problem it works exactly the same. It is an object that stores text strings. It contains 12 different text strings and its index starts at zero.

meses[0]  -> Enero
meses[1]  -> Febrero
meses[11] -> Diciembre

Now, your task involves doing some mathematical calculation in each iteration of the cycle for . As indicated by your problem "consider each month as a counter that increases by 1 each time the cycle is repeated" .

I recommend that you do the mathematical calculation corresponding to the solution of your problem within the for cycle and print the result with the cout object. Example:

for(int i = 0; i < meses.size(); i++) {
    cout << meses[i] << "|" << ganancia * capital << endl;
}

I told you that StackOverflow is not a place for someone to solve tasks for you, but you can consult help with problems with your code.

    
answered by 30.08.2018 в 07:55