Go Back   CodingForums.com > :: Computing & Sciences > Computer Programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-08-2012, 03:46 AM   PM User | #1
Cheeseboy
Regular Coder

 
Join Date: Mar 2006
Posts: 160
Thanks: 0
Thanked 0 Times in 0 Posts
Cheeseboy is an unknown quantity at this point
counting error c++

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
Code:
#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;
}
Cheeseboy is offline   Reply With Quote
Old 09-08-2012, 04:35 AM   PM User | #2
Spookster
Supreme Overlord


 
Spookster's Avatar
 
Join Date: May 2002
Location: Marion, IA USA
Posts: 6,222
Thanks: 4
Thanked 80 Times in 79 Posts
Spookster will become famous soon enough
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>
__________________
Spookster
CodingForums Supreme Overlord
All Hail Spookster
Who gave you that Ugging infraction? Yeah that's right it was me!
Spookster is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:59 PM.


Advertisement
Log in to turn off these ads.