My program does correctly output the number of months it takes to repay the loan amount. could someone please help me figure this part out. I think its not producing the correct output because I have the wrong information inside the loop I'm trying to use.
What do you expect this loop to do?
Either it doesn't execute at all (if i <1), or it will never terminate (if i>= 1) since you never modify I.
PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post. http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
Modify "I" like how? How would I make so that the equation is false eventually. This is the real problem I am having with this chapter-- writing an correct LCV.
I think what you could do is make a loop at the beginning of the program and then when I is lower than 1, you just restart the loop and ask the user to input the data again.
while(true)
{
cout << "Enter loan amount: ";
cin >> L;
cout << endl;
cout << "Enter interest rate: ";
cin >> I;
cout << endl;
cout << "Enter the monthly payment desired: ";
cin >> MP;
cout << endl;
if (I < 1)
{
continue;
}
else
{
//Rest of your code here, followed by a break
break;
}
Or if you want to stick to the current structure and only want the user to adjust I, you can do this:
1 2 3 4 5 6 7 8 9 10 11 12 13
while (I < 1)
{
cout << "Interest rate has to be higher than 1: ";
cin >> I;
cout << endl;
}
// after the user finally found out which interger he should not enter for I, your script continues and spits out the balance.
// I don't think you want to loop the code below, right?
cout << " bla1 ";
MP = ((I / 100) * L) / M;
cout << "Remaining balance is: $" << MP
<< endl;