課題用に以下のプログラムを作成しました。元本、最低利率、最高利率、利息を積み立てる年数を入力できるはずです。
テスト後、最高利率を .06、.6 などと入力しない限り、すべて問題なく動作します。何らかの理由で、最高利率が表示されません。最低利率として .06 を入力すると正常に表示され、.06 よりも高い最高利率を使用すると、.06 の金額が表示されます。私に問題を提示する他の量はありません。
これを修正するために何を変更する必要があるかを理解するのを手伝ってくれる人はいますか?
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
//variables & named constants
int principal = 0;
double minimumInterest = 0.0;
double maximumInterest = 0.0;
int yearBase = 1;
int years = 0;
double balance = 0.0;
//inputs
cout << "Enter the beginning principal: $";
cin >> principal;
cout << "Enter the minimum interest rate: ";
cin >> minimumInterest;
cout << "Enter the maximum interest rate: ";
cin >> maximumInterest;
cout << "Enter the number of years the interest will accumlate: ";
cin >> years;
//calculations & loop
do
{
cout << "Year " << yearBase << ":" << endl;
for (double rate = minimumInterest; rate <= maximumInterest; rate += .01)
{
balance = principal * pow(1 + rate, yearBase);
//display rate with zero decimal places
cout << fixed << setprecision(0);
cout << " Rate " << rate * 100 << "%: $";
//display balance with two decimal places
cout << setprecision(2) << balance << endl;
}
//update years counter
yearBase +=1;
} while (yearBase <= years);
system("pause");
return 0;
}