0
Я пытался понять это на некоторое время, и я думаю, что это имеет какое-то отношение к значениям, которые я использую для расчетов. Я не совсем знаком с сложными интересами, поэтому я не уверен, что я ошибаюсь. Любая помощь будет оценена по достоинству.C++ Почему это приводит к неправильному сложному проценту?
#include <iostream>
#include <cmath>
using namespace std;
double interest_credit_card(double initial_balance, double interest_rate, int payment_months);
// Calculates interest on a credit card account according to initial balance,
//interest rate, and number of payment months.
int main()
{
double initial_balance, interest_rate;
int payment_months;
char answer;
do
{
cout << "Enter your initial balace: \n";
cin >> initial_balance;
cout << "For how many months will you be making payments?\n";
cin >> payment_months;
cout << "What is your interest rate (as a percent)?: %\n";
cin >> interest_rate;
cout << endl;
cout << "You will be paying: $ " << interest_credit_card(initial_balance, interest_rate, payment_months) << endl;
cout << "Would you like to try again? (Y/N)\n";
cin >> answer;
}while (answer == 'Y' || answer == 'y');
cout << "Good-Bye.\n";
return 0;
}
double interest_credit_card(double initial_balance, double interest_rate, int payment_months)
{
double compound_interest, compounding, compounding2, compounding3, compounding4;
while(payment_months > 0)
{
initial_balance = initial_balance + (initial_balance * interest_rate/100.0);
compounding = (interest_rate /12);
compounding2 = compounding + 1;
compounding3 = interest_rate * (payment_months/12);
compounding4 = pow(compounding2, compounding3);
compound_interest = initial_balance * compounding4;
initial_balance = initial_balance + compound_interest;
payment_months--;
}
return initial_balance;
}
Входы и ожидаемые результаты:
Enter your initial balance: 1000
For how many months will you be making payments?: 7
What is your interest rate (as a percent)?: 9
You will be paying: $1053.70
Пожалуйста, укажите пример входных данных, ожидаемый результат и то, что вы получили. – user2807083
Вы уверены, что вы оставите остаток в 'payment_months/12' в порядке? – MikeCAT
Я консультировался с несколькими сайтами, и я не могу понять, какую формулу вы используете для расчета сложных процентов, похоже, что вы перепутали некоторые вещи. –