Witam,
Bardzo proszę o podpowiedź co robie nie tak oraz jaki jest prostszy sposób na taką kalkulacje?
Write a program to calculate how the stock investment went over 4 years. One should be able to load the invested amount, as well as the percentage change for each of the four years. Assume that the increased/decreased sum is reinvested each year.
If you invest 10 000 SEK and the value change was 3,5%, 4,7%, -2,1% and 0,4%, the application should print 10 651,32 SEK.
#include <iostream>
#include <iomanip>
using namespace std;
void stock();
int main()
{
char answer;
do
{
stock();
cout << "\nOne more time (Y/N) ?";
cin >> answer;
} while (answer == 'Y' || answer == 'y');
return 0;
}
void stock()
{
int invested = 0;
float p1, p2, p3, p4;
float year1, year2, year3, year4;
cout << "Enter sum invested: ";
cin >> invested;
cout << "Enter four value changes in percent: ";
cin >> p1 >> p2 >> p3 >> p4;
year1 = invested * (1 + p1/100);
year2 = year1 * (1 + p2/100);
year3 = year2 * (1 + p3/100);
year4 = year3 * (1 + p4/100);
cout << "The total sum is : " << setprecision(2) << fixed << year4 << endl;
}