Hi all,

This program is compiled successfully but it does not do what it is meant to do

# include <iostream>
using namespace std;

int main ()
{
	double interest_py, interest_pm, month_pay, loan, interest_due=0;
	int counter=0;


	cout << "Loan amount =";
	cin >> loan;
	  
	cout << "Interst per year =";
	cin >> interest_py;

	interest_pm = interest_py/100/12;

	cout << "Monthly payment = ";
	cin >> month_pay;

	interest_due = interest_pm*loan;

	while (month_pay < interest_due)
	{ 
		cout << "Monthly payment is too low"
	         << "if you want to repay your loan; increase payment" 
			 << endl;

	     cin >> month_pay;

	     interest_due = interest_pm*loan;
	}

	do 
	{ 
	  loan = loan-(month_pay-interest_due);
	  interest_due = interest_pm*loan;
	  counter++;
	}
	while (loan != 0); // end of do while

	if (loan=0)
		cout << "Months to repay the loan =" << counter <<endl;

	return 0;
}//end

I modified this part :

do 
	{ 
	  loan = loan + interest_due -(month_pay-interest_due);
	  interest_due = interest_pm*loan;
	  counter++;
	}

	while (loan != 0); // end of do while

but still, there's some issue

every thing is correct except this

it is always false

if (loan=0)
            cout << "Months to repay the loan =" << counter <<endl

it should be

if (  loan == 0)
            cout << "Months to repay the loan =" << counter <<endl

simple assignment operator makes life misearable :) ...

hope your problem is solved.

oh yeah .. you're right :D

that was one of the mistakes lol

I figured out there are some semantic mistakes

thanks mate

The compiler shouldn't have just ignored this :/
What compiler do you use? Just so that i don't ever use it.

lol I'm using visual C++

what do you use ??

The compiler shouldn't have just ignored this :/
What compiler do you use? Just so that i don't ever use it.

= vs. == being ignored has nothing to do with the compiler. It has to do with the compiler flags you set as far as a warning level. I had the same question a while ago. If you want to catch = vs. ==, adjust the compiler flags.

http://www.daniweb.com/forums/thread127558.html

aha .. thanks for the clarification :)

pspwxp fan, almost made me doubt my compiler :P

The compiler shouldn't have just ignored this :/
What compiler do you use? Just so that i don't ever use it.

If(a=b) is a valid syntax , atmost compiler can provide an warning.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.