Trying to stop this endless loop

It just stays in an endless loop, and i though my > statement would end the loop. Any suggestions are welcomes, thank you all in advance for trying to help!


#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
using namespace std;

int main()
{
double initialInv, intRate, amtDesired, years, endAmt, begAmt, increase;

cout << "To find out how many years it will take to achieve the investment\nreturn you desire, please input the amount you are investing, the\n";
cout << "yearly interest rate (as an interger), and the amount you wish to achieve.\n";
cin >> initialInv >> intRate >> amtDesired;
years = 1;
cout << left << setw(10) << "Years" << left << setw(18) << "Initial Amount" << left << setw(9) << "End Amount";
endAmt = 0;
if(!cin.good()) // user gave bad input
{
cin.ignore(1000); // dump the bad input
cin.clear(); // reset cin to be in a good state
}
while (endAmt < amtDesired)
{
intRate = intRate / 100;
increase = initialInv * intRate;
endAmt = increase + initialInv;
begAmt = initialInv;
initialInv = endAmt;
years++;
cout << left << setw(10) << years << left << setw(18) << fixed << setprecision(2) << begAmt;
cout << left << setw(9) << fixed << setprecision(2) << endAmt;
}



return 0;
}
Your interest rate is constantly being decreased... move the intRate = intRate/100; out of the loop.
Last edited on
thank you, that fixed it, cant believe i missed that.
it happens to the best of us.
Topic archived. No new replies allowed.