...

View Full Version : counting error c++



Cheeseboy
09-08-2012, 03:46 AM
Hello all,

I am working on a program which calculates loan information. For some reason the program keeps looping even though I have set the loop variables to stop when month count gets to 60 or the balance is a 0 or less than. Looking for some hints.

Thanks

#include <iostream>
#include <iomanip>

using namespace std;

double loanbalance;
double interestrate;
double payment;
double newloanamt;
int monthnum= 0;
int i=1;
float fBalance;





int main ()
{
cout << "Starting loan balance: $";
cin >> loanbalance;
cout << "Annual interest rate: %";
cin >> interestrate;
cout << "Monthly payment: $";
cin >> payment;




cout << " \nMonth\tBalance" << endl;
while (monthnum < 60 || loanbalance<=0){
monthnum = monthnum + 1;
loanbalance = loanbalance*(interestrate/12) + loanbalance - payment;

cout << monthnum << "\t" << loanbalance << endl;


}


return 0;
}

Spookster
09-08-2012, 04:35 AM
It would be pretty easy to determine the problem if you run your code in a debugger. That should always be the first step to perform when your application is not working as expected. When I help people with their code I first do a quick glance over the code to see if it is something obvious. If I don't see it in the first glance I compile it and run it in a debugger so I can step through the code and watch the values of each variable. </rant>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum