Hello everyone,

i need to enter a value into a savings account paying 7% interest and €1,000 is withdrawn from the account at the end of each year. How many years are required for the savings account to be depleted?

here's wat i did, but the loop not working:

``````#include <stdio.h>
#include <stdlib.h>
#define interest 0.07

int main()
{
int salary;
float final_sum;

do
{
printf("\n Enter a Value");
scanf("%d",&salary);

final_sum = (salary-(salary*interest))-1000;

printf("%0.02f",final_sum);
}
while (final_sum <1000);

system("PAUSE");
return(0);
}``````

thanks

I suppose you need to enter the salary once?? Or do you have to enter it every time (that's not in the specs)
If the former is the case then you need to change (decrement) your final sum inside the loop. Otherwise how will it ever become less than 1000 (unless you are entering a very small amount)

Think about it and post back. And please be more specific. For e.g give us a sample output and the output that you are getting. It will help us solve your problem faster.

Also is it the complete code? You said you need to print the time but here you are printing the final_sum??

NP-complete is absolutely right.

Before you sit infront of the computer and start coding you'd better figure out what you really want to do and how would you solve the problem. Design an algorithm.

hello,

€15000 is deposited into a savings account paying 7% interest and €1,000 is withdrawn from the account at the end of each year. How many years are required for the savings account to be depleted?

here i use an example 15000 and the user need to enter it only once, the it will decrease till the account will be depleted. So the output must be the time (years), how much it take for the 15000 to be depleted.

hope this help

and Yes its not the complete code, i just try this at first,
but the Loop not working

thank you very much for helping

right. Just as I thought it to be. In that case, read my first advice and think of ways to DECREMENT your final_sum INSIDE the do loop.

You must read the input once, in this case 15.000. Then use a loop to calculate the amount remaining. When the finalSum < 0 the loop terminates. The loop uses a counter representing the years, increases it every time the loop executes.

Then print the counter.

I hope you have got enough hints....now start coding....

Good Luck....

hello,
here's what has done:

``````#include <stdio.h>
#include <stdlib.h>
#define interest 0.05

int main()
{
int salary;
float final_sum;
int counter=0;

printf("\n Enter a Value");
scanf("%d",&salary);

while (salary > 1000)
{
salary = (salary+(salary*interest))-1000;
counter++;
}
printf("%d\n",salary);
printf("%d\n",counter);

system("PAUSE");
return(0);
}``````

how i'll display salary into decimal number, cause when the calculation is done, we will get decimal numbers

thanks

You must read the input once, in this case 15.000. Then use a loop to calculate the amount remaining. When the finalSum < 0 the loop terminates. The loop uses a counter representing the years, increases it every time the loop executes.

Then print the counter.

hello, i did it, take a look please
thanks

``````int main()
{
float f=10.5678;
printf("%f\n",f);
}``````

Now if you want more precision when you are printing the floating point number google for print and you will find ways to do that

You cant hold decimal values in integer type. Try float or double.

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.