Simple question

Pages: 12
I need help over this question..

The constant percentage method of computing depreciation of an asset is based on the assumption
that the depreciation charge at the end of each year is a fixed percentage of the book value of the
asset at the beginning of the year. This assumption leads to the following relationship:

S = C(1 ─ d)n

where C = original cost of assed
d = depreciation rate per year
n = number of years
S = book value of the end of n years.

Write a program to compute the number of years of useful life of an asset given the original cost,
depreciation rate, and book value at the end of its useful life (called scrap value). The program
should also display the book value at the end of each year until the end of its useful life. Your
program should allow the user to repeat this calculation as often as the user wishes.

What is the help you need? They have given you an equation, in the form of S as the dependent variable. Just re-arrange it, to get an expression for number of years (n) viz n=S/(C*(1-d)), and use it in your program.
i dont get how the equation to be used
so n=S/(C*(1-d)) its fine to use?
Yes... It will
compute the number of years of useful life of an asset
after taking cost, rate and scrap value as input.
As far as the book value at the end of each year is concerned, you'll have to put it in a loop, somewhat like:

1
2
3
4
5
6
int i, book_value;
for (i=1; i<=n; i++)
{
        book_value=(C*(1-d)*i);
        cout<<"\nThe value of the book after "<<i<<" years is "<<book_value;
}


Put this entire program in do-while loop for
Your program should allow the user to repeat this calculation as often as the user wishes.
Last edited on
Thank for your guidance.
You're always welcome! :) Glad to be of help.
can put the whole coding of this question....Having some difficulties doing this question...
How about if the equation given is n=S = C(1 ─ d)n ?
How do i use the maths funtions?
and should i declare years variable as float or int?
Kwong can u put ur coding here...
S = C(1 - d)n, solving for n? logC(1 - d)(S) = n. You might want to see a math help forum for these types of questions (not that most of us can't do high school algebra. :)
Last edited on
Take the ln of both sides. Solve for n, then turn it into c++:
1
2
3
4
5
6
7
8
9
10
11
#include <cmath>

int main()
{
	float S, C, d, n;
	//Initialize S, C, D here
	
	n = (log(S) - log(C))/log(1-d);

	return 0;
}


Here I've used floats, I did so because money doesn't need to be very precise (only 2 decimal points). I didn't use ints because I want the decimal and there is no log() function for ints (in standard) and doubles are sort of a waste of memory for what we are doing. To use the log() function, you need to include <math.h> for C or <cmath> for C++.

FYI: The log function is base e.

http://www.cplusplus.com/reference/clibrary/cmath/log/
Last edited on
Yup, for n, use log:

 
n= (log(S) - log(C))/(1-d);


And for the loop, use pow function:

1
2
3
4
5
6
float book_value
int i;

for (i=1; i<=n; i++)
book_value=(C*(pow((1-d), n)));
cout<<\nThe value of the book after"<<i<<" years is: "<<book_value; 


And yeah, everything should be float, 'cause number of years is not necessarily integral, and neither is rate, principal amount or value at any given time...
do we have to calculate the number of years and then calculate the book years???
Yes, you'll have to... else you won't have an upper limit condition in your for-loop...
could post the whole coding...i have a bit trouble wit the coding....

can we use function in this question....
Why do you want a function? Its a straightforward program... Doesn't really require a function... And NO, no one will post the entire code... this forum is to help people out, not do their homework for them!
k then...y i do get ans= nan wen i use the

n= (log(S) - log(C))/(1-d);
I'm sorry, but what's "nan"???
NaN stands for Not a Number.
It can happen when you divide by zero and things like that.

#include <iostream>
#include <cmath>
using namespace std;

int main()

{
float S,C,d,n;

cout<<"Please insert original cost="<<"\n";
cin>>C;

cout<< "Please insert depreciation rate= "<<"\n";
cin>>d;

cout<<"Please insert book value= "<<"\n";
cin>>S;

n=(log (S)-log(C))/log(1-d);

cout<<"number of years="<<n;


}


the answer i get for n is n=nan...I dun have any idea wat nan is...
Last edited on
Pages: 12