Дано задание под номером 7. Первые два года рассчитывает правильно, а вот на 10 год получается такой ответ = 10998.4 В чем моя ошибка?
#include <iostream>
using namespace std;
int main()
{
int year;
double procent, capital, begin;
cout << "Enter the initial contribution: ";
cin >> begin;
cout << "Enter the number of year: ";
cin >> year;
cout << "Enter the interest rate: ";
cin >> procent;
for (int i = 0; i < year; i++)
{
begin = (i * 165) + begin;
capital = begin + (begin * (procent * 0.01));
}
cout << "In " << year << " you will receive " << capital << " dollars" <<
endl;
system("pause");
return 0;
}
У вас проблема в алгоритме, т.е. он изначально неверен:
capital = begin
for(int i = 0; i < years; i++){
capital += capital * (procent / 100 )
}
cout << "In " << year << " you will receive " << capital << " dollars" << endl;
Т.е. по факту вам нужно удалить первую строчку в цикле
Сборка персонального компьютера от Artline: умный выбор для современных пользователей