My program is working but is not displaying the correct results. It is displaying 5% instead of 2, 3, and 4 % for each year. If someone could tell me what I am doing incorrectly that would be fantastic.
Thanks in advance.
Here is my code
Code:#include <iostream> #include <iomanip> #include <cmath> using namespace std; int main() { int principal = 1000; int years = 1; //counter double balance = 0.0; double rate = 0.02; do //begin loop { while (rate < .05) rate = rate +.01; cout << "Year" << years << ":" << endl; { balance = principal * pow(1 + rate, years); //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; } //end for //years counter years += 1; }while (years < 6); //system("pause") return 0; } //end of main function
C++ code - 41 lines - codepad