C++ Loan repayment issues












-2















Not sure where I am going wrong. I have looked up the exact same problem a couple of times on this site and others. Here is the question...




You have just purchased a stereo system that cost $1,000 on the following credit plan: no down payment, an interest rate of 18% per year (1.5% per month), and monthly payments of $50. The monthly payment of $50 is used to pay the interest, and whatever is left is used to pay part of the remaining debt. Hence, the first month you pay 1.5% of $1,000 in interest. That is $15 in interest. The remaining $35 is deducted from your debt, which leaves you with a debt of $965.00. The next month you pay interest of 1.5% of $965.00, which is $14.48. Hence, you can deduct $35.52 (which is $50 - $14.48) from the amount you owe.




Here is my code.



using namespace std;

int main(){

double interest;
double interestpaid;
double principle=1000.0;
const double rate= 0.015;
const int moneydue = 50;
int month = 0;



cout << "Repayment Plan"<<'n';

while(principle > 0)
{
interestpaid = principle*rate;
interest += interestpaid;
principle -= moneydue + interestpaid;
month++;
}


cout << month << interest << principle <<'n';
cout <<"It will take" << month << "months to pay off" <<'n';
cout <<"The last principle payment is" << principle << endl;
return 0;
}


Here's what I'm getting:



What I get



And here's what I need:



What I need][2










share|improve this question

























  • what is the problem with your code?

    – Ted Lyngmo
    Nov 24 '18 at 4:41











  • @Spicymoose Hi there, welcome to SO. Can you clarify: I have looked up the exact same problem what the "exact same problem" is?

    – TrebuchetMS
    Nov 24 '18 at 4:45











  • First, don't post images from an external web site. Second, it is obvious your code could not produce multiple lines of output as you have shown. How could it when the cout statements fall outside the while loop?

    – PaulMcKenzie
    Nov 24 '18 at 4:49













  • (and this has nothing to do with your task, but does your teacher actually tell you to using namespace std;)?

    – Ted Lyngmo
    Nov 24 '18 at 4:52













  • @TedLyngmo Probably. There are still evil <expletive deleted>ers out there forcing students to use TurboC++ (Yes, a programming tool so old that it hung out with Care Bears) and teach C89 to unsuspecting kids who think they are learning C++.

    – user4581301
    Nov 24 '18 at 5:04
















-2















Not sure where I am going wrong. I have looked up the exact same problem a couple of times on this site and others. Here is the question...




You have just purchased a stereo system that cost $1,000 on the following credit plan: no down payment, an interest rate of 18% per year (1.5% per month), and monthly payments of $50. The monthly payment of $50 is used to pay the interest, and whatever is left is used to pay part of the remaining debt. Hence, the first month you pay 1.5% of $1,000 in interest. That is $15 in interest. The remaining $35 is deducted from your debt, which leaves you with a debt of $965.00. The next month you pay interest of 1.5% of $965.00, which is $14.48. Hence, you can deduct $35.52 (which is $50 - $14.48) from the amount you owe.




Here is my code.



using namespace std;

int main(){

double interest;
double interestpaid;
double principle=1000.0;
const double rate= 0.015;
const int moneydue = 50;
int month = 0;



cout << "Repayment Plan"<<'n';

while(principle > 0)
{
interestpaid = principle*rate;
interest += interestpaid;
principle -= moneydue + interestpaid;
month++;
}


cout << month << interest << principle <<'n';
cout <<"It will take" << month << "months to pay off" <<'n';
cout <<"The last principle payment is" << principle << endl;
return 0;
}


Here's what I'm getting:



What I get



And here's what I need:



What I need][2










share|improve this question

























  • what is the problem with your code?

    – Ted Lyngmo
    Nov 24 '18 at 4:41











  • @Spicymoose Hi there, welcome to SO. Can you clarify: I have looked up the exact same problem what the "exact same problem" is?

    – TrebuchetMS
    Nov 24 '18 at 4:45











  • First, don't post images from an external web site. Second, it is obvious your code could not produce multiple lines of output as you have shown. How could it when the cout statements fall outside the while loop?

    – PaulMcKenzie
    Nov 24 '18 at 4:49













  • (and this has nothing to do with your task, but does your teacher actually tell you to using namespace std;)?

    – Ted Lyngmo
    Nov 24 '18 at 4:52













  • @TedLyngmo Probably. There are still evil <expletive deleted>ers out there forcing students to use TurboC++ (Yes, a programming tool so old that it hung out with Care Bears) and teach C89 to unsuspecting kids who think they are learning C++.

    – user4581301
    Nov 24 '18 at 5:04














-2












-2








-2








Not sure where I am going wrong. I have looked up the exact same problem a couple of times on this site and others. Here is the question...




You have just purchased a stereo system that cost $1,000 on the following credit plan: no down payment, an interest rate of 18% per year (1.5% per month), and monthly payments of $50. The monthly payment of $50 is used to pay the interest, and whatever is left is used to pay part of the remaining debt. Hence, the first month you pay 1.5% of $1,000 in interest. That is $15 in interest. The remaining $35 is deducted from your debt, which leaves you with a debt of $965.00. The next month you pay interest of 1.5% of $965.00, which is $14.48. Hence, you can deduct $35.52 (which is $50 - $14.48) from the amount you owe.




Here is my code.



using namespace std;

int main(){

double interest;
double interestpaid;
double principle=1000.0;
const double rate= 0.015;
const int moneydue = 50;
int month = 0;



cout << "Repayment Plan"<<'n';

while(principle > 0)
{
interestpaid = principle*rate;
interest += interestpaid;
principle -= moneydue + interestpaid;
month++;
}


cout << month << interest << principle <<'n';
cout <<"It will take" << month << "months to pay off" <<'n';
cout <<"The last principle payment is" << principle << endl;
return 0;
}


Here's what I'm getting:



What I get



And here's what I need:



What I need][2










share|improve this question
















Not sure where I am going wrong. I have looked up the exact same problem a couple of times on this site and others. Here is the question...




You have just purchased a stereo system that cost $1,000 on the following credit plan: no down payment, an interest rate of 18% per year (1.5% per month), and monthly payments of $50. The monthly payment of $50 is used to pay the interest, and whatever is left is used to pay part of the remaining debt. Hence, the first month you pay 1.5% of $1,000 in interest. That is $15 in interest. The remaining $35 is deducted from your debt, which leaves you with a debt of $965.00. The next month you pay interest of 1.5% of $965.00, which is $14.48. Hence, you can deduct $35.52 (which is $50 - $14.48) from the amount you owe.




Here is my code.



using namespace std;

int main(){

double interest;
double interestpaid;
double principle=1000.0;
const double rate= 0.015;
const int moneydue = 50;
int month = 0;



cout << "Repayment Plan"<<'n';

while(principle > 0)
{
interestpaid = principle*rate;
interest += interestpaid;
principle -= moneydue + interestpaid;
month++;
}


cout << month << interest << principle <<'n';
cout <<"It will take" << month << "months to pay off" <<'n';
cout <<"The last principle payment is" << principle << endl;
return 0;
}


Here's what I'm getting:



What I get



And here's what I need:



What I need][2







c++






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 24 '18 at 11:02









TrebuchetMS

2,2781622




2,2781622










asked Nov 24 '18 at 4:39









SpicymooseSpicymoose

1




1













  • what is the problem with your code?

    – Ted Lyngmo
    Nov 24 '18 at 4:41











  • @Spicymoose Hi there, welcome to SO. Can you clarify: I have looked up the exact same problem what the "exact same problem" is?

    – TrebuchetMS
    Nov 24 '18 at 4:45











  • First, don't post images from an external web site. Second, it is obvious your code could not produce multiple lines of output as you have shown. How could it when the cout statements fall outside the while loop?

    – PaulMcKenzie
    Nov 24 '18 at 4:49













  • (and this has nothing to do with your task, but does your teacher actually tell you to using namespace std;)?

    – Ted Lyngmo
    Nov 24 '18 at 4:52













  • @TedLyngmo Probably. There are still evil <expletive deleted>ers out there forcing students to use TurboC++ (Yes, a programming tool so old that it hung out with Care Bears) and teach C89 to unsuspecting kids who think they are learning C++.

    – user4581301
    Nov 24 '18 at 5:04



















  • what is the problem with your code?

    – Ted Lyngmo
    Nov 24 '18 at 4:41











  • @Spicymoose Hi there, welcome to SO. Can you clarify: I have looked up the exact same problem what the "exact same problem" is?

    – TrebuchetMS
    Nov 24 '18 at 4:45











  • First, don't post images from an external web site. Second, it is obvious your code could not produce multiple lines of output as you have shown. How could it when the cout statements fall outside the while loop?

    – PaulMcKenzie
    Nov 24 '18 at 4:49













  • (and this has nothing to do with your task, but does your teacher actually tell you to using namespace std;)?

    – Ted Lyngmo
    Nov 24 '18 at 4:52













  • @TedLyngmo Probably. There are still evil <expletive deleted>ers out there forcing students to use TurboC++ (Yes, a programming tool so old that it hung out with Care Bears) and teach C89 to unsuspecting kids who think they are learning C++.

    – user4581301
    Nov 24 '18 at 5:04

















what is the problem with your code?

– Ted Lyngmo
Nov 24 '18 at 4:41





what is the problem with your code?

– Ted Lyngmo
Nov 24 '18 at 4:41













@Spicymoose Hi there, welcome to SO. Can you clarify: I have looked up the exact same problem what the "exact same problem" is?

– TrebuchetMS
Nov 24 '18 at 4:45





@Spicymoose Hi there, welcome to SO. Can you clarify: I have looked up the exact same problem what the "exact same problem" is?

– TrebuchetMS
Nov 24 '18 at 4:45













First, don't post images from an external web site. Second, it is obvious your code could not produce multiple lines of output as you have shown. How could it when the cout statements fall outside the while loop?

– PaulMcKenzie
Nov 24 '18 at 4:49







First, don't post images from an external web site. Second, it is obvious your code could not produce multiple lines of output as you have shown. How could it when the cout statements fall outside the while loop?

– PaulMcKenzie
Nov 24 '18 at 4:49















(and this has nothing to do with your task, but does your teacher actually tell you to using namespace std;)?

– Ted Lyngmo
Nov 24 '18 at 4:52







(and this has nothing to do with your task, but does your teacher actually tell you to using namespace std;)?

– Ted Lyngmo
Nov 24 '18 at 4:52















@TedLyngmo Probably. There are still evil <expletive deleted>ers out there forcing students to use TurboC++ (Yes, a programming tool so old that it hung out with Care Bears) and teach C89 to unsuspecting kids who think they are learning C++.

– user4581301
Nov 24 '18 at 5:04





@TedLyngmo Probably. There are still evil <expletive deleted>ers out there forcing students to use TurboC++ (Yes, a programming tool so old that it hung out with Care Bears) and teach C89 to unsuspecting kids who think they are learning C++.

– user4581301
Nov 24 '18 at 5:04












1 Answer
1






active

oldest

votes


















1














To debug your code, for every iteration of your while(principle > 0) loop,
you should print out how much goes to the interest, and how much goes to the principal. You are miscalculating how much money goes towards the principle payment. Consider this



while(principle > 0)
{
interestpaid = principle*rate;
interest += interestpaid;
double principalPayment = moneydue - interestpaid;
principle -= principalPayment;
month++;
}





share|improve this answer
























  • I tried doing as suggested, but still can't seem to get the proper answers.

    – Spicymoose
    Nov 24 '18 at 6:02











  • make sure that you understand the problem statement correctly. Are you compounding interest correctly? Is it supposed to be compounded continuously, monthly, daily? Suggestion provided in my answer gets you values close enough to what you expect.

    – HappyKeyboard
    Nov 24 '18 at 15:11











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53455184%2fc-loan-repayment-issues%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














To debug your code, for every iteration of your while(principle > 0) loop,
you should print out how much goes to the interest, and how much goes to the principal. You are miscalculating how much money goes towards the principle payment. Consider this



while(principle > 0)
{
interestpaid = principle*rate;
interest += interestpaid;
double principalPayment = moneydue - interestpaid;
principle -= principalPayment;
month++;
}





share|improve this answer
























  • I tried doing as suggested, but still can't seem to get the proper answers.

    – Spicymoose
    Nov 24 '18 at 6:02











  • make sure that you understand the problem statement correctly. Are you compounding interest correctly? Is it supposed to be compounded continuously, monthly, daily? Suggestion provided in my answer gets you values close enough to what you expect.

    – HappyKeyboard
    Nov 24 '18 at 15:11
















1














To debug your code, for every iteration of your while(principle > 0) loop,
you should print out how much goes to the interest, and how much goes to the principal. You are miscalculating how much money goes towards the principle payment. Consider this



while(principle > 0)
{
interestpaid = principle*rate;
interest += interestpaid;
double principalPayment = moneydue - interestpaid;
principle -= principalPayment;
month++;
}





share|improve this answer
























  • I tried doing as suggested, but still can't seem to get the proper answers.

    – Spicymoose
    Nov 24 '18 at 6:02











  • make sure that you understand the problem statement correctly. Are you compounding interest correctly? Is it supposed to be compounded continuously, monthly, daily? Suggestion provided in my answer gets you values close enough to what you expect.

    – HappyKeyboard
    Nov 24 '18 at 15:11














1












1








1







To debug your code, for every iteration of your while(principle > 0) loop,
you should print out how much goes to the interest, and how much goes to the principal. You are miscalculating how much money goes towards the principle payment. Consider this



while(principle > 0)
{
interestpaid = principle*rate;
interest += interestpaid;
double principalPayment = moneydue - interestpaid;
principle -= principalPayment;
month++;
}





share|improve this answer













To debug your code, for every iteration of your while(principle > 0) loop,
you should print out how much goes to the interest, and how much goes to the principal. You are miscalculating how much money goes towards the principle payment. Consider this



while(principle > 0)
{
interestpaid = principle*rate;
interest += interestpaid;
double principalPayment = moneydue - interestpaid;
principle -= principalPayment;
month++;
}






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 24 '18 at 4:59









HappyKeyboardHappyKeyboard

1066




1066













  • I tried doing as suggested, but still can't seem to get the proper answers.

    – Spicymoose
    Nov 24 '18 at 6:02











  • make sure that you understand the problem statement correctly. Are you compounding interest correctly? Is it supposed to be compounded continuously, monthly, daily? Suggestion provided in my answer gets you values close enough to what you expect.

    – HappyKeyboard
    Nov 24 '18 at 15:11



















  • I tried doing as suggested, but still can't seem to get the proper answers.

    – Spicymoose
    Nov 24 '18 at 6:02











  • make sure that you understand the problem statement correctly. Are you compounding interest correctly? Is it supposed to be compounded continuously, monthly, daily? Suggestion provided in my answer gets you values close enough to what you expect.

    – HappyKeyboard
    Nov 24 '18 at 15:11

















I tried doing as suggested, but still can't seem to get the proper answers.

– Spicymoose
Nov 24 '18 at 6:02





I tried doing as suggested, but still can't seem to get the proper answers.

– Spicymoose
Nov 24 '18 at 6:02













make sure that you understand the problem statement correctly. Are you compounding interest correctly? Is it supposed to be compounded continuously, monthly, daily? Suggestion provided in my answer gets you values close enough to what you expect.

– HappyKeyboard
Nov 24 '18 at 15:11





make sure that you understand the problem statement correctly. Are you compounding interest correctly? Is it supposed to be compounded continuously, monthly, daily? Suggestion provided in my answer gets you values close enough to what you expect.

– HappyKeyboard
Nov 24 '18 at 15:11


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53455184%2fc-loan-repayment-issues%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

Calculate evaluation metrics using cross_val_predict sklearn

Insert data from modal to MySQL (multiple modal on website)