2 Replies - 274 Views - Last Post: 04 September 2012 - 03:32 PM Rate Topic: -----

#1 zachkt  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 19-July 12

What am I doing wrong with this loop

Posted 04 September 2012 - 03:04 PM

I am trying to write a program that tells me how many months it will take to pay off a loan, and the total interest that will be paid. When i run this, it doesnt tell me the final number of months, instead it just gives me the total interest at month 1, month 2 etc.


#include <iostream>
using namespace std;
int main ()
{
	double debt = 100;
	double interest;
	double pay;
	double totalinterest = 0;
	int month = 0;

	cout << " You have bought a stereo that costs $1000 with the following credit plan:" << endl;
	cout << endl;
	cout << " No down payment, an interest rate of 18% per year and monthly payments of $50." << endl;
	cout << endl;

	while (debt>0)
	{
	interest = debt * .015;
	pay = 50 - interest;
	debt = debt - pay;
	month = month + 1;
	totalinterest = totalinterest + interest;

	cout << "It will take you" << month << "months to pay off the debt." << endl;
	cout << "The total interest paid in the end will be $" << totalinterest << endl;
	 }
	

	

	return 0;

}




Is This A Good Question/Topic? 0
  • +

Replies To: What am I doing wrong with this loop

#2 jimblumberg  Icon User is offline

  • member icon


Reputation: 4025
  • View blog
  • Posts: 12,423
  • Joined: 25-December 09

Re: What am I doing wrong with this loop

Posted 04 September 2012 - 03:22 PM

One of the issues is that you have assigned debt a value of 100 instead of 1000. The other is that your cout statements should probably be after the loop, not inside the loop.

Jim
Was This Post Helpful? 0
  • +
  • -

#3 zachkt  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 19-July 12

Re: What am I doing wrong with this loop

Posted 04 September 2012 - 03:32 PM

View Postjimblumberg, on 04 September 2012 - 03:22 PM, said:

One of the issues is that you have assigned debt a value of 100 instead of 1000. The other is that your cout statements should probably be after the loop, not inside the loop.

Jim


You're the man! I actually had the cout statement outside the loop before i posted this but it wasnt giving me any result. The "100" was definitely the issue. Thank you
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1