Calculating paystring for loan data
Example:
Input: cpi = 100.0, payments = [100.0, 94.0, 90.0, 100.0, 200.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0 ]
Output: paystring = [0, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]
Explanation: Since the first payment was 100.0 and that is greater than or equal to cpi - 5.0 (95.0) then the first element in the output is 0. Then the next element is 1 since 94.0 is less than cpi - 5.0 (95.0) i.e. missed a payment, then since the next element 90.0 is less than cpi - 5.0 (95.0) i.e. missed another payment than now we are at 2 (or 2 total missed payments). Then in the next element we had 100 then that counts as 1 payment made so now we made that payment that was due but we still didn't cover the other two payments from the prior month so we are still at 2. Then the process continues.
I have this so far:
double cpi = 100.0;
std::vector<double> payments = 100.0, 94.0, 90.0, 100.0, 200.0, 300.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0 ;
std::vector<int> paystring(payments.size(), 0);
int count = 0;
for (int i = 0; i < payments.size(); ++i)
if (payments[i] <= cpi - 5.0)
paystring[i] = ++count;
else
paystring[i] = count;
for (auto it : paystring)
std::cout << it << " ";
Although, this is not correct since it fails to update count when I made lets say the full payment or more than the due amount (cpi). I just want to know what I need to change in my logic to make this work. Let me know if the example provided is unclear.
For example say I have
Input: cpi = 100.0, payments = [100.0, 94.0, 90.0, 100.0, 200.0, 100.0, 300.0, 100.0, 100.0, 100.0, 100.0, 100.0 ]
Output: [0, 1, 2, 2, 1, 0, 0, 0, 0, 0, 0, 0]
But I get
[0, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]
Here is a few more examples that are correct:

c++ string vector
add a comment |
Example:
Input: cpi = 100.0, payments = [100.0, 94.0, 90.0, 100.0, 200.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0 ]
Output: paystring = [0, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]
Explanation: Since the first payment was 100.0 and that is greater than or equal to cpi - 5.0 (95.0) then the first element in the output is 0. Then the next element is 1 since 94.0 is less than cpi - 5.0 (95.0) i.e. missed a payment, then since the next element 90.0 is less than cpi - 5.0 (95.0) i.e. missed another payment than now we are at 2 (or 2 total missed payments). Then in the next element we had 100 then that counts as 1 payment made so now we made that payment that was due but we still didn't cover the other two payments from the prior month so we are still at 2. Then the process continues.
I have this so far:
double cpi = 100.0;
std::vector<double> payments = 100.0, 94.0, 90.0, 100.0, 200.0, 300.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0 ;
std::vector<int> paystring(payments.size(), 0);
int count = 0;
for (int i = 0; i < payments.size(); ++i)
if (payments[i] <= cpi - 5.0)
paystring[i] = ++count;
else
paystring[i] = count;
for (auto it : paystring)
std::cout << it << " ";
Although, this is not correct since it fails to update count when I made lets say the full payment or more than the due amount (cpi). I just want to know what I need to change in my logic to make this work. Let me know if the example provided is unclear.
For example say I have
Input: cpi = 100.0, payments = [100.0, 94.0, 90.0, 100.0, 200.0, 100.0, 300.0, 100.0, 100.0, 100.0, 100.0, 100.0 ]
Output: [0, 1, 2, 2, 1, 0, 0, 0, 0, 0, 0, 0]
But I get
[0, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]
Here is a few more examples that are correct:

c++ string vector
it fails to update count when I made lets say the full payment or more than the due amount (cpi). -- So you wrote the program, knowing what you wrote wouldn't satisfy all the requirements? Or did you discover the issue just now and you want someone to debug the code for you?
– PaulMcKenzie
Nov 13 '18 at 1:13
100.0 and that is less than or equal to cpi - 5.0 (95.0) - please explain it.
– S.M.
Nov 13 '18 at 1:14
@PaulMcKenzie I wrote the program initially to satisfy the first example, I then thought of another example to make it break. I am wondering what I need to (logic wise) to make sure I update count properly.
– Snorrlaxxx
Nov 13 '18 at 1:16
1
@Snorrlaxxx -- Writing code and seeing there is an example where the code breaks -- hate to tell you, but this is one of the things you learn when you write programs -- redesign. It isn't an anomaly to find out that initial designs are flawed in some way and then need to be adjusted.
– PaulMcKenzie
Nov 13 '18 at 1:21
add a comment |
Example:
Input: cpi = 100.0, payments = [100.0, 94.0, 90.0, 100.0, 200.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0 ]
Output: paystring = [0, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]
Explanation: Since the first payment was 100.0 and that is greater than or equal to cpi - 5.0 (95.0) then the first element in the output is 0. Then the next element is 1 since 94.0 is less than cpi - 5.0 (95.0) i.e. missed a payment, then since the next element 90.0 is less than cpi - 5.0 (95.0) i.e. missed another payment than now we are at 2 (or 2 total missed payments). Then in the next element we had 100 then that counts as 1 payment made so now we made that payment that was due but we still didn't cover the other two payments from the prior month so we are still at 2. Then the process continues.
I have this so far:
double cpi = 100.0;
std::vector<double> payments = 100.0, 94.0, 90.0, 100.0, 200.0, 300.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0 ;
std::vector<int> paystring(payments.size(), 0);
int count = 0;
for (int i = 0; i < payments.size(); ++i)
if (payments[i] <= cpi - 5.0)
paystring[i] = ++count;
else
paystring[i] = count;
for (auto it : paystring)
std::cout << it << " ";
Although, this is not correct since it fails to update count when I made lets say the full payment or more than the due amount (cpi). I just want to know what I need to change in my logic to make this work. Let me know if the example provided is unclear.
For example say I have
Input: cpi = 100.0, payments = [100.0, 94.0, 90.0, 100.0, 200.0, 100.0, 300.0, 100.0, 100.0, 100.0, 100.0, 100.0 ]
Output: [0, 1, 2, 2, 1, 0, 0, 0, 0, 0, 0, 0]
But I get
[0, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]
Here is a few more examples that are correct:

c++ string vector
Example:
Input: cpi = 100.0, payments = [100.0, 94.0, 90.0, 100.0, 200.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0 ]
Output: paystring = [0, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]
Explanation: Since the first payment was 100.0 and that is greater than or equal to cpi - 5.0 (95.0) then the first element in the output is 0. Then the next element is 1 since 94.0 is less than cpi - 5.0 (95.0) i.e. missed a payment, then since the next element 90.0 is less than cpi - 5.0 (95.0) i.e. missed another payment than now we are at 2 (or 2 total missed payments). Then in the next element we had 100 then that counts as 1 payment made so now we made that payment that was due but we still didn't cover the other two payments from the prior month so we are still at 2. Then the process continues.
I have this so far:
double cpi = 100.0;
std::vector<double> payments = 100.0, 94.0, 90.0, 100.0, 200.0, 300.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0 ;
std::vector<int> paystring(payments.size(), 0);
int count = 0;
for (int i = 0; i < payments.size(); ++i)
if (payments[i] <= cpi - 5.0)
paystring[i] = ++count;
else
paystring[i] = count;
for (auto it : paystring)
std::cout << it << " ";
Although, this is not correct since it fails to update count when I made lets say the full payment or more than the due amount (cpi). I just want to know what I need to change in my logic to make this work. Let me know if the example provided is unclear.
For example say I have
Input: cpi = 100.0, payments = [100.0, 94.0, 90.0, 100.0, 200.0, 100.0, 300.0, 100.0, 100.0, 100.0, 100.0, 100.0 ]
Output: [0, 1, 2, 2, 1, 0, 0, 0, 0, 0, 0, 0]
But I get
[0, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]
Here is a few more examples that are correct:

c++ string vector
c++ string vector
edited Nov 13 '18 at 11:55
DanAl
533317
533317
asked Nov 13 '18 at 1:08
SnorrlaxxxSnorrlaxxx
14311
14311
it fails to update count when I made lets say the full payment or more than the due amount (cpi). -- So you wrote the program, knowing what you wrote wouldn't satisfy all the requirements? Or did you discover the issue just now and you want someone to debug the code for you?
– PaulMcKenzie
Nov 13 '18 at 1:13
100.0 and that is less than or equal to cpi - 5.0 (95.0) - please explain it.
– S.M.
Nov 13 '18 at 1:14
@PaulMcKenzie I wrote the program initially to satisfy the first example, I then thought of another example to make it break. I am wondering what I need to (logic wise) to make sure I update count properly.
– Snorrlaxxx
Nov 13 '18 at 1:16
1
@Snorrlaxxx -- Writing code and seeing there is an example where the code breaks -- hate to tell you, but this is one of the things you learn when you write programs -- redesign. It isn't an anomaly to find out that initial designs are flawed in some way and then need to be adjusted.
– PaulMcKenzie
Nov 13 '18 at 1:21
add a comment |
it fails to update count when I made lets say the full payment or more than the due amount (cpi). -- So you wrote the program, knowing what you wrote wouldn't satisfy all the requirements? Or did you discover the issue just now and you want someone to debug the code for you?
– PaulMcKenzie
Nov 13 '18 at 1:13
100.0 and that is less than or equal to cpi - 5.0 (95.0) - please explain it.
– S.M.
Nov 13 '18 at 1:14
@PaulMcKenzie I wrote the program initially to satisfy the first example, I then thought of another example to make it break. I am wondering what I need to (logic wise) to make sure I update count properly.
– Snorrlaxxx
Nov 13 '18 at 1:16
1
@Snorrlaxxx -- Writing code and seeing there is an example where the code breaks -- hate to tell you, but this is one of the things you learn when you write programs -- redesign. It isn't an anomaly to find out that initial designs are flawed in some way and then need to be adjusted.
– PaulMcKenzie
Nov 13 '18 at 1:21
it fails to update count when I made lets say the full payment or more than the due amount (cpi). -- So you wrote the program, knowing what you wrote wouldn't satisfy all the requirements? Or did you discover the issue just now and you want someone to debug the code for you?
– PaulMcKenzie
Nov 13 '18 at 1:13
it fails to update count when I made lets say the full payment or more than the due amount (cpi). -- So you wrote the program, knowing what you wrote wouldn't satisfy all the requirements? Or did you discover the issue just now and you want someone to debug the code for you?
– PaulMcKenzie
Nov 13 '18 at 1:13
100.0 and that is less than or equal to cpi - 5.0 (95.0) - please explain it.
– S.M.
Nov 13 '18 at 1:14
100.0 and that is less than or equal to cpi - 5.0 (95.0) - please explain it.
– S.M.
Nov 13 '18 at 1:14
@PaulMcKenzie I wrote the program initially to satisfy the first example, I then thought of another example to make it break. I am wondering what I need to (logic wise) to make sure I update count properly.
– Snorrlaxxx
Nov 13 '18 at 1:16
@PaulMcKenzie I wrote the program initially to satisfy the first example, I then thought of another example to make it break. I am wondering what I need to (logic wise) to make sure I update count properly.
– Snorrlaxxx
Nov 13 '18 at 1:16
1
1
@Snorrlaxxx -- Writing code and seeing there is an example where the code breaks -- hate to tell you, but this is one of the things you learn when you write programs -- redesign. It isn't an anomaly to find out that initial designs are flawed in some way and then need to be adjusted.
– PaulMcKenzie
Nov 13 '18 at 1:21
@Snorrlaxxx -- Writing code and seeing there is an example where the code breaks -- hate to tell you, but this is one of the things you learn when you write programs -- redesign. It isn't an anomaly to find out that initial designs are flawed in some way and then need to be adjusted.
– PaulMcKenzie
Nov 13 '18 at 1:21
add a comment |
1 Answer
1
active
oldest
votes
You have a condition that if payment is too low, penalty is added, the customer is one month behind.
Add another condition: If over payment is made, for example $200, you want to give customer credit, that puts the customer one month ahead. Then add a condition that the customer is not ahead by a negative count.
std::vector<double> payments =
100, 94, 90, 100, 200, 100, 300, 100, 100, 100, 100, 100
//"0 1 1 0 -1 0 -2 0 0 0 0 0 <-penalty
//"0 1 2 2 1 1 0 0 0 0 0 0 <-penalty sum
;
double cpi = 100.0;
for(int i = 0; i < payments.size(); ++i)
double payment = payments[i];
if(payment <= (cpi - 5.0))
//one month behind on payment
count++;
while((payment > cpi) && count)
//customer made large payment.
//allow count to decrease.
//but count cannot be less than zero
count--;
payment -= cpi;
paystring[i] = count;
Ouput for 100, 94, 90, 100, 200, 100, 100, 100, 100, 100, 100, 100:
0 1 2 2 2 2 2 2 2 2 2 2 //expected output
0 1 2 2 1 1 1 1 1 1 1 1 //result
Ouput for 100, 94, 90, 100, 200, 100, 300, 100, 100, 100, 100, 100:
0 1 2 2 1 0 0 0 0 0 0 0 //expected output
0 1 2 2 1 1 0 0 0 0 0 0 //result
My output is not the same, maybe the expected output is incorrect or you left something out. Note the 6th payment is 100, so there shouldn't be any change for that index.
Thank you for your answer, I have a condition that the payment just needs to be at least the cpi - 5.0, does your solution consider that? Also, for the balance = payment - 100 can that just be generalized to balance = payment - cpi?
– Snorrlaxxx
Nov 13 '18 at 16:39
Yes it looks atcpi - 5.0I modify the code to make look more like yours. Notice the difference is thatcountcan go down. As I said earlier, this doesn't exactly match your expected output, it doesn't work for the first data set either.
– Barmak Shemirani
Nov 13 '18 at 16:56
Why does it not work with first data set?
– Snorrlaxxx
Nov 13 '18 at 16:58
I believe your solutions works actually, is it okay to change the 100.0 to cpi?
– Snorrlaxxx
Nov 13 '18 at 17:01
Yes, I did that in the second edit. I removed the100from the calculation.
– Barmak Shemirani
Nov 13 '18 at 17:07
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53272324%2fcalculating-paystring-for-loan-data%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
You have a condition that if payment is too low, penalty is added, the customer is one month behind.
Add another condition: If over payment is made, for example $200, you want to give customer credit, that puts the customer one month ahead. Then add a condition that the customer is not ahead by a negative count.
std::vector<double> payments =
100, 94, 90, 100, 200, 100, 300, 100, 100, 100, 100, 100
//"0 1 1 0 -1 0 -2 0 0 0 0 0 <-penalty
//"0 1 2 2 1 1 0 0 0 0 0 0 <-penalty sum
;
double cpi = 100.0;
for(int i = 0; i < payments.size(); ++i)
double payment = payments[i];
if(payment <= (cpi - 5.0))
//one month behind on payment
count++;
while((payment > cpi) && count)
//customer made large payment.
//allow count to decrease.
//but count cannot be less than zero
count--;
payment -= cpi;
paystring[i] = count;
Ouput for 100, 94, 90, 100, 200, 100, 100, 100, 100, 100, 100, 100:
0 1 2 2 2 2 2 2 2 2 2 2 //expected output
0 1 2 2 1 1 1 1 1 1 1 1 //result
Ouput for 100, 94, 90, 100, 200, 100, 300, 100, 100, 100, 100, 100:
0 1 2 2 1 0 0 0 0 0 0 0 //expected output
0 1 2 2 1 1 0 0 0 0 0 0 //result
My output is not the same, maybe the expected output is incorrect or you left something out. Note the 6th payment is 100, so there shouldn't be any change for that index.
Thank you for your answer, I have a condition that the payment just needs to be at least the cpi - 5.0, does your solution consider that? Also, for the balance = payment - 100 can that just be generalized to balance = payment - cpi?
– Snorrlaxxx
Nov 13 '18 at 16:39
Yes it looks atcpi - 5.0I modify the code to make look more like yours. Notice the difference is thatcountcan go down. As I said earlier, this doesn't exactly match your expected output, it doesn't work for the first data set either.
– Barmak Shemirani
Nov 13 '18 at 16:56
Why does it not work with first data set?
– Snorrlaxxx
Nov 13 '18 at 16:58
I believe your solutions works actually, is it okay to change the 100.0 to cpi?
– Snorrlaxxx
Nov 13 '18 at 17:01
Yes, I did that in the second edit. I removed the100from the calculation.
– Barmak Shemirani
Nov 13 '18 at 17:07
add a comment |
You have a condition that if payment is too low, penalty is added, the customer is one month behind.
Add another condition: If over payment is made, for example $200, you want to give customer credit, that puts the customer one month ahead. Then add a condition that the customer is not ahead by a negative count.
std::vector<double> payments =
100, 94, 90, 100, 200, 100, 300, 100, 100, 100, 100, 100
//"0 1 1 0 -1 0 -2 0 0 0 0 0 <-penalty
//"0 1 2 2 1 1 0 0 0 0 0 0 <-penalty sum
;
double cpi = 100.0;
for(int i = 0; i < payments.size(); ++i)
double payment = payments[i];
if(payment <= (cpi - 5.0))
//one month behind on payment
count++;
while((payment > cpi) && count)
//customer made large payment.
//allow count to decrease.
//but count cannot be less than zero
count--;
payment -= cpi;
paystring[i] = count;
Ouput for 100, 94, 90, 100, 200, 100, 100, 100, 100, 100, 100, 100:
0 1 2 2 2 2 2 2 2 2 2 2 //expected output
0 1 2 2 1 1 1 1 1 1 1 1 //result
Ouput for 100, 94, 90, 100, 200, 100, 300, 100, 100, 100, 100, 100:
0 1 2 2 1 0 0 0 0 0 0 0 //expected output
0 1 2 2 1 1 0 0 0 0 0 0 //result
My output is not the same, maybe the expected output is incorrect or you left something out. Note the 6th payment is 100, so there shouldn't be any change for that index.
Thank you for your answer, I have a condition that the payment just needs to be at least the cpi - 5.0, does your solution consider that? Also, for the balance = payment - 100 can that just be generalized to balance = payment - cpi?
– Snorrlaxxx
Nov 13 '18 at 16:39
Yes it looks atcpi - 5.0I modify the code to make look more like yours. Notice the difference is thatcountcan go down. As I said earlier, this doesn't exactly match your expected output, it doesn't work for the first data set either.
– Barmak Shemirani
Nov 13 '18 at 16:56
Why does it not work with first data set?
– Snorrlaxxx
Nov 13 '18 at 16:58
I believe your solutions works actually, is it okay to change the 100.0 to cpi?
– Snorrlaxxx
Nov 13 '18 at 17:01
Yes, I did that in the second edit. I removed the100from the calculation.
– Barmak Shemirani
Nov 13 '18 at 17:07
add a comment |
You have a condition that if payment is too low, penalty is added, the customer is one month behind.
Add another condition: If over payment is made, for example $200, you want to give customer credit, that puts the customer one month ahead. Then add a condition that the customer is not ahead by a negative count.
std::vector<double> payments =
100, 94, 90, 100, 200, 100, 300, 100, 100, 100, 100, 100
//"0 1 1 0 -1 0 -2 0 0 0 0 0 <-penalty
//"0 1 2 2 1 1 0 0 0 0 0 0 <-penalty sum
;
double cpi = 100.0;
for(int i = 0; i < payments.size(); ++i)
double payment = payments[i];
if(payment <= (cpi - 5.0))
//one month behind on payment
count++;
while((payment > cpi) && count)
//customer made large payment.
//allow count to decrease.
//but count cannot be less than zero
count--;
payment -= cpi;
paystring[i] = count;
Ouput for 100, 94, 90, 100, 200, 100, 100, 100, 100, 100, 100, 100:
0 1 2 2 2 2 2 2 2 2 2 2 //expected output
0 1 2 2 1 1 1 1 1 1 1 1 //result
Ouput for 100, 94, 90, 100, 200, 100, 300, 100, 100, 100, 100, 100:
0 1 2 2 1 0 0 0 0 0 0 0 //expected output
0 1 2 2 1 1 0 0 0 0 0 0 //result
My output is not the same, maybe the expected output is incorrect or you left something out. Note the 6th payment is 100, so there shouldn't be any change for that index.
You have a condition that if payment is too low, penalty is added, the customer is one month behind.
Add another condition: If over payment is made, for example $200, you want to give customer credit, that puts the customer one month ahead. Then add a condition that the customer is not ahead by a negative count.
std::vector<double> payments =
100, 94, 90, 100, 200, 100, 300, 100, 100, 100, 100, 100
//"0 1 1 0 -1 0 -2 0 0 0 0 0 <-penalty
//"0 1 2 2 1 1 0 0 0 0 0 0 <-penalty sum
;
double cpi = 100.0;
for(int i = 0; i < payments.size(); ++i)
double payment = payments[i];
if(payment <= (cpi - 5.0))
//one month behind on payment
count++;
while((payment > cpi) && count)
//customer made large payment.
//allow count to decrease.
//but count cannot be less than zero
count--;
payment -= cpi;
paystring[i] = count;
Ouput for 100, 94, 90, 100, 200, 100, 100, 100, 100, 100, 100, 100:
0 1 2 2 2 2 2 2 2 2 2 2 //expected output
0 1 2 2 1 1 1 1 1 1 1 1 //result
Ouput for 100, 94, 90, 100, 200, 100, 300, 100, 100, 100, 100, 100:
0 1 2 2 1 0 0 0 0 0 0 0 //expected output
0 1 2 2 1 1 0 0 0 0 0 0 //result
My output is not the same, maybe the expected output is incorrect or you left something out. Note the 6th payment is 100, so there shouldn't be any change for that index.
edited Nov 13 '18 at 17:04
answered Nov 13 '18 at 8:48
Barmak ShemiraniBarmak Shemirani
21k42145
21k42145
Thank you for your answer, I have a condition that the payment just needs to be at least the cpi - 5.0, does your solution consider that? Also, for the balance = payment - 100 can that just be generalized to balance = payment - cpi?
– Snorrlaxxx
Nov 13 '18 at 16:39
Yes it looks atcpi - 5.0I modify the code to make look more like yours. Notice the difference is thatcountcan go down. As I said earlier, this doesn't exactly match your expected output, it doesn't work for the first data set either.
– Barmak Shemirani
Nov 13 '18 at 16:56
Why does it not work with first data set?
– Snorrlaxxx
Nov 13 '18 at 16:58
I believe your solutions works actually, is it okay to change the 100.0 to cpi?
– Snorrlaxxx
Nov 13 '18 at 17:01
Yes, I did that in the second edit. I removed the100from the calculation.
– Barmak Shemirani
Nov 13 '18 at 17:07
add a comment |
Thank you for your answer, I have a condition that the payment just needs to be at least the cpi - 5.0, does your solution consider that? Also, for the balance = payment - 100 can that just be generalized to balance = payment - cpi?
– Snorrlaxxx
Nov 13 '18 at 16:39
Yes it looks atcpi - 5.0I modify the code to make look more like yours. Notice the difference is thatcountcan go down. As I said earlier, this doesn't exactly match your expected output, it doesn't work for the first data set either.
– Barmak Shemirani
Nov 13 '18 at 16:56
Why does it not work with first data set?
– Snorrlaxxx
Nov 13 '18 at 16:58
I believe your solutions works actually, is it okay to change the 100.0 to cpi?
– Snorrlaxxx
Nov 13 '18 at 17:01
Yes, I did that in the second edit. I removed the100from the calculation.
– Barmak Shemirani
Nov 13 '18 at 17:07
Thank you for your answer, I have a condition that the payment just needs to be at least the cpi - 5.0, does your solution consider that? Also, for the balance = payment - 100 can that just be generalized to balance = payment - cpi?
– Snorrlaxxx
Nov 13 '18 at 16:39
Thank you for your answer, I have a condition that the payment just needs to be at least the cpi - 5.0, does your solution consider that? Also, for the balance = payment - 100 can that just be generalized to balance = payment - cpi?
– Snorrlaxxx
Nov 13 '18 at 16:39
Yes it looks at
cpi - 5.0 I modify the code to make look more like yours. Notice the difference is that count can go down. As I said earlier, this doesn't exactly match your expected output, it doesn't work for the first data set either.– Barmak Shemirani
Nov 13 '18 at 16:56
Yes it looks at
cpi - 5.0 I modify the code to make look more like yours. Notice the difference is that count can go down. As I said earlier, this doesn't exactly match your expected output, it doesn't work for the first data set either.– Barmak Shemirani
Nov 13 '18 at 16:56
Why does it not work with first data set?
– Snorrlaxxx
Nov 13 '18 at 16:58
Why does it not work with first data set?
– Snorrlaxxx
Nov 13 '18 at 16:58
I believe your solutions works actually, is it okay to change the 100.0 to cpi?
– Snorrlaxxx
Nov 13 '18 at 17:01
I believe your solutions works actually, is it okay to change the 100.0 to cpi?
– Snorrlaxxx
Nov 13 '18 at 17:01
Yes, I did that in the second edit. I removed the
100 from the calculation.– Barmak Shemirani
Nov 13 '18 at 17:07
Yes, I did that in the second edit. I removed the
100 from the calculation.– Barmak Shemirani
Nov 13 '18 at 17:07
add a comment |
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53272324%2fcalculating-paystring-for-loan-data%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
it fails to update count when I made lets say the full payment or more than the due amount (cpi). -- So you wrote the program, knowing what you wrote wouldn't satisfy all the requirements? Or did you discover the issue just now and you want someone to debug the code for you?
– PaulMcKenzie
Nov 13 '18 at 1:13
100.0 and that is less than or equal to cpi - 5.0 (95.0) - please explain it.
– S.M.
Nov 13 '18 at 1:14
@PaulMcKenzie I wrote the program initially to satisfy the first example, I then thought of another example to make it break. I am wondering what I need to (logic wise) to make sure I update count properly.
– Snorrlaxxx
Nov 13 '18 at 1:16
1
@Snorrlaxxx -- Writing code and seeing there is an example where the code breaks -- hate to tell you, but this is one of the things you learn when you write programs -- redesign. It isn't an anomaly to find out that initial designs are flawed in some way and then need to be adjusted.
– PaulMcKenzie
Nov 13 '18 at 1:21