try this

``while(nbalance>1 || nbalance==1)``
``````while (nbalance>=1) {
System.out.println ("Month: "+ month +   " Balance: " + nbalance +     " Total Payments: " + pay);
month++;
nbalance = (nbalance * interest) - pay;
nbalance--;
pay = pay+100;
}``````

why should it have nbalance--?
also change the position of pay and nbalance operation

Well, nbalance needs to decrease, but that was the wrong choice.
I changed the positions, but is this what you meant?

``````while (nbalance>=1) {
nbalance = (nbalance * interest) - pay;
pay = pay+100;
System.out.println ("Month: "+ month +   " Balance: " + nbalance +     " Total Payments: " + pay);
month++;
}``````

try this

``while(nbalance>1 || nbalance==1)``

Still the same issue.

try this

``while(nbalance>1 || nbalance==1)``

If you take a look at the desired output, you will notice that the balance will go negative at constant payments of \$100.00...so I'm thinking we'll have to re-do the while loop and still try to solve this issue.

``nbalance = (nbalance * interest) - pay;``

after this operation nbalance becomes less than 1

the problem is not the while loop itself but rather the operation of the doubles inside the loop

``nbalance = (nbalance * interest) - pay;``

after this operation nbalance becomes less than 1

Okay, but it still only prints out the first line and not the rest...

You still don't get it do you
915*.015 will be equal to....
Then add the value to nbalance

Don't just save the value to nbalance

You still don't get it do you
915*.015 will be equal to....
Then add the value to nbalance

Don't just save the value to nbalance

Ok, I get that part.

``nbalance = (nbalance * interest) + nbalance - pay;``

Now the input is:

Enter the monthly payment:
100
Month: 1 Balance: 915.0 Total Payments: 100.0
Month: 2 Balance: 828.725 Total Payments: 200.0
Month: 3 Balance: 641.155875 Total Payments: 300.0
Month: 4 Balance: 350.773213125 Total Payments: 400.0

Which is still incorrect...

can you post the operation to get the output...not the code but the solution
cause It's hard for me to guess on my side

can you post the operation to get the output...not the code but the solution
cause It's hard for me to guess on my side

The solution, as in how the output is supposed to be?

Enter the monthly payment: 100
Month: 1 balance: 915.0 total payments: 100.0
Month: 2 balance: 828.73 total payments: 200.0
Month: 3 balance: 741.16 total payments: 300.0
Month: 4 balance: 652.27 total payments: 400.0
Month: 5 balance: 562.06 total payments: 500.0
Month: 6 balance: 470.49 total payments: 600.0
Month: 7 balance: 377.54 total payments: 700.0
Month: 8 balance: 283.21 total payments: 800.0
Month: 9 balance: 187.46 total payments: 900.0
Month: 10 balance: 90.27 total payments: 1000.0
Month: 11 balance: -8.38 total payments: 1100.0

The solution, as in how the output is supposed to be?

Enter the monthly payment: 100
Month: 1 balance: 915.0 total payments: 100.0
Month: 2 balance: 828.73 total payments: 200.0
Month: 3 balance: 741.16 total payments: 300.0
Month: 4 balance: 652.27 total payments: 400.0
Month: 5 balance: 562.06 total payments: 500.0
Month: 6 balance: 470.49 total payments: 600.0
Month: 7 balance: 377.54 total payments: 700.0
Month: 8 balance: 283.21 total payments: 800.0
Month: 9 balance: 187.46 total payments: 900.0
Month: 10 balance: 90.27 total payments: 1000.0
Month: 11 balance: -8.38 total payments: 1100.0

What I meant to say is the solution on how did 915 become 828 then 741 then 652 and so on cause as you can see your current operation cannot do this

If you don't know the solution by hand then try not to code it yet

What I meant to say is the solution on how did 915 become 828 then 741 then 652 and so on cause as you can see your current operation cannot do this

Oh, that's not how my input looks like right now. That is how it is supposed to look like.

Every month the left over balance is to be multiplied by 1.5% interest, and then subtracted by a \$100 payment...

then subtract it by 100

``nbalance = (nbalance * interest) + nbalance - 100;``

though it defeats the purpose of using pay in your operation...
but hey as long as you get your desired output you should be happy

then subtract it by 100

``nbalance = (nbalance * interest) + nbalance - 100;``

though it defeats the purpose of using pay in your operation...
but hey as long as you get your desired output you should be happy

Hey thanks, it worked! But...it doesn't print out this line, which is supposed be the last line in the output:

Month: 11 balance: -8.38 total payments: 1100.0

``````System.out.println ("Month: "+ month + " Balance: " + nbalance + " Total Payments: " + pay);
while(nbalance>1.00){
double value = nbalance * .015;
pay+=100;
nbalance = (value+nbalance) -100;
System.out.println ("Month: "+ month + " Balance: " + nbalance + " Total Payments: " + pay);
month++;
}``````
``````System.out.println ("Month: "+ month + " Balance: " + nbalance + " Total Payments: " + pay);
while(nbalance>1.00){
double value = nbalance * .015;
pay+=100;
nbalance = (value+nbalance) -100;
System.out.println ("Month: "+ month + " Balance: " + nbalance + " Total Payments: " + pay);
month++;
}``````

Ok, this gets the -8.37, but skips the first output line. The output resides to:

Month: 1 Balance: 828.725 Total Payments: 100.0
Month: 2 Balance: 741.155875 Total Payments: 200.0
Month: 3 Balance: 652.273213125 Total Payments: 300.0
Month: 4 Balance: 562.057311321875 Total Payments: 400.0
Month: 5 Balance: 470.4881709917031 Total Payments: 500.0
Month: 6 Balance: 377.54549355657866 Total Payments: 600.0
Month: 7 Balance: 283.20867595992735 Total Payments: 700.0
Month: 8 Balance: 187.4568060993263 Total Payments: 800.0
Month: 9 Balance: 90.26865819081618 Total Payments: 900.0
Month: 10 Balance: -8.377311936321576 Total Payments: 1000.0

Ok, this gets the -8.37, but skips the first output line. The output resides to:

Month: 1 Balance: 828.725 Total Payments: 100.0
Month: 2 Balance: 741.155875 Total Payments: 200.0
Month: 3 Balance: 652.273213125 Total Payments: 300.0
Month: 4 Balance: 562.057311321875 Total Payments: 400.0
Month: 5 Balance: 470.4881709917031 Total Payments: 500.0
Month: 6 Balance: 377.54549355657866 Total Payments: 600.0
Month: 7 Balance: 283.20867595992735 Total Payments: 700.0
Month: 8 Balance: 187.4568060993263 Total Payments: 800.0
Month: 9 Balance: 90.26865819081618 Total Payments: 900.0
Month: 10 Balance: -8.377311936321576 Total Payments: 1000.0

Did you just made the code so that you can make an exact replica of the output?
Cause I was thinking you were trying to make a bank or investment like program :-O

Oh, okay, but we still had to move month++ before the second println for it to work. Thanks! One more thing, if I were to change the user input to 500, instead of 100, then it wouldn't work. I believe this is because we put 100 everywhere...

Did you just made the code so that you can make an exact replica of the output?
Cause I was thinking you were trying to make a bank or investment like program :-O

I was trying to make a proper which the user can input any amount as the monthly payment desired, then the program to calculate it from that...

Oh, okay, but we still had to move month++ before the second println for it to work. Thanks! One more thing, if I were to change the user input to 500, instead of 100, then it wouldn't work. I believe this is because we put 100 everywhere...

Hahaha:D:D:D:D:D:D:D:D:D
you make me laugh!!!
of course it will not give the same result like 100 that's why I'm telling you to have a solution by hand before trying to code it... It's like you just want to have the same output as stated but you did not mention how your program really works like when the user wants to have another input...

Most of the given in the code is predefined

Now all our coding could be just a waste

How would I modify the program so that it would go according to the user's input...as I was trying to explain..

My final advice my friend is to know the algorithm before coding

Hahaha:D:D:D:D:D:D:D:D:D
you make me laugh!!!
of course it will not give the same result like 100 that's why I'm telling you to have a solution by hand before trying to code it... It's like you just want to have the same output as stated but you did not mention how your program really works like when the user wants to have another input...

Most of the given in the code is predefined

Now all our coding could be just a waste

Hahahaha, but if you read my inital post, you will see everything is thoroughly explained.

My final advice my friend is to know the algorithm before coding

I edited the program so that it would go by the user's input, it does it perfectly, except the pay isn't accumulating right...

``````class CreditCardBill{
public static void main (String[] args){
Scanner input = new Scanner(System.in);
int month = 1;
System.out.println ("Enter the monthly payment: ");
double pay = input.nextInt();
double left = 1000;
double interest = 0.015;
double balance = (left * interest) + left;
double nbalance = (balance - pay);
System.out.println ("Month: "+ month + " Balance: " + nbalance + " Total Payments: " + pay);
while(nbalance>1.00){
double value = nbalance * .015;
month++;
double total = pay + pay;
nbalance = (value+nbalance) -pay;
System.out.println ("Month: "+ month + " Balance: " + nbalance + " Total Payments: " + total);
}
}
}``````

THE OUTPUT:

Enter the monthly payment:
500
Month: 1 Balance: 515.0 Total Payments: 500.0
Month: 2 Balance: 22.725000000000023 Total Payments: 1000.0
Month: 3 Balance: -476.934125 Total Payments: 1000.0
>

you only posted the output you want
not the real program description

you only posted the output you want
not the real program description

Haha, if you scroll down a bit, in the inital post, it says:

"Say that you owe the credit card company \$1000.00. The company charges you 1.5% per month on the unpaid balance. You have decided to stop using the card and to pay off the debt by making a monthly payment of N dollars a month. Write a program that asks for the monthy payment, then writes out the balance and total payments so far for every succeeding month until the balance is zero or less.

For each month, calculate the interest due on the unpaid balance. Then calculate the new balance by adding the interest and subtracting the payment."

Haha, if you scroll down a bit, in the inital post, it says:

"Say that you owe the credit card company \$1000.00. The company charges you 1.5% per month on the unpaid balance. You have decided to stop using the card and to pay off the debt by making a monthly payment of N dollars a month. Write a program that asks for the monthy payment, then writes out the balance and total payments so far for every succeeding month until the balance is zero or less.

For each month, calculate the interest due on the unpaid balance. Then calculate the new balance by adding the interest and subtracting the payment."

Then the fool here is me I should have initially and repeatedly told you to have a working solution before coding

ehem..anyway just store the value in a separate variable

``````int payement = pay;
System.out.println ("Month: "+ month + " Balance: " + nbalance + " Total Payments: " + pay);
while(nbalance>1.00){
double value = nbalance * .015;
payement+=100;
nbalance = (value+nbalance) - pay;
System.out.println ("Month: "+ month + " Balance: " + nbalance + " Total Payments: " + pay);
month++;
}``````
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.